Javascript in public web block

I am creating a web block to be reused in other applications, there is a javascript file uploaded in resources under App1 folder and linked using AddJavascript in HTTPRequestHandler. Everything works in the application where the web block resides.

When it is referenced in another application, during runtime the javascript file cannot be found because it is now supposed to be at the App2 folder.

How can the correct folder location be set in the web block so it will work in other applications?


Hi Stanley,

If the Resourses are in App1 why doens't your url have a full path? "/App1/scripts/somejavascript.js"
(note I'm assuming from your problem that you have something like "scripts/somejavascript.js")

As a side note, check the Integrating a JQuery plugin page in the Academy.
Unless there are many javascript files I recommend using the block javascript approach explain there instead of the resources as it works better than the HTTPRequestHandler approach. Expecially to avoid import order problems between multiple libraries and will guarantiee that a script is only added once per page.
Here is also a related topic, check my replies there for some reasoning.

João Rosado

Thanks for the informative links, it make sense to moved the javascript within the web block, I just do that and it works.