Post Closed
4721
Views
8
Comments
Solved
Adding a external .js (javascript) file to Web application
Question

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>

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2021-07-09 11-03-39
Roshan Nayak

Thanks Killian

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Raj,

For this you can use the HTTPRequestHandler Extension's AddJavaScriptTag

UserImage.jpg
Raj Manoharan

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Raj,

That is explained here in the documentation.

UserImage.jpg
Raj Manoharan

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.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
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.

2021-07-09 11-03-39
Roshan Nayak

Thanks Killian

UserImage.jpg
Raj Manoharan

Hi Kilian,

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

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

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 :).