Adding a external .js (javascript) file to Web application

Adding a external .js (javascript) file to Web application

  

I would like to reuse javascript files, is it possible to include the .js files to the web application. by adding script tag like <script src="[location]"> </script>

Hi Raj,

For this you can use the HTTPRequestHandler Extension's AddJavaScriptTag

Hi Kilian, 

Thanks for your reply, AddJavaScriptTag is expecting an JavaScriptURL,  could you help me understand how to add the .js file to the web application so that an URL can be provided to the input.

Hi Raj,

That is explained here in the documentation.

Hi Kilian,

 Based on the link it appears that the java script has to be manually and copied to a web block or screen. So is my understanding correct that there is no direct way to include a .js file to the web application?  (unless it is hosted in some other server, which can be accessed using an URL). 

To put my requirement in simple words, I have a local .js file, I want to be able to use it in my outsystem web application, is it possible to use it with help of  HTTPRequestHandler.AddJavaScriptTag. Any pointers in this direction would be really helpful.

Solution

Hi Raj,

You can include your JavaScript file as a Resource (Data tab, bottom). Specify the Deploy Action to "Deploy to Target Directory", and add a Target Directory (e.g. "js"). I think the AddJavaScriptTag can then be used with a relative URL (js/YourFile.js). If not, you can use the full Runtime Path as shown.

Solution

Hi Kilian,

Thank you so much it worked, this is exactly what I was looking for, apologize my ignorance.

Hi Raj,

Great to hear you got it working! And don't worry about not knowing things, that's what the forum's for! Happy coding :).