How to insert external JavaScript code into body section of html?

Hi team,

I'm currently trying to use an open-source JavaScript library in my OutSystems Web project and those external JavaScript code MUST be added to the end of <body> tag in html.

It seems that if I try to add JavaScript code to my application using the method shown in the picture attached, those code will be inserted into the <head> section automatically.

I have to give up developing on OutSystems if I can't use this JavaScript library so are there any option to put JS code just before the end of <body> section?

Thank you in advance.


Hi Mofeng,

Please try below approach - 

function loadScript() {
    var scriptToAdd = document.createElement('script');
    scriptToAdd.type = 'text/javascript';
    scriptToAdd.src = 'your script';//add you external script here
    document.body.appendChild(scriptToAdd);
}

window.onload = loadScript;

Please add above code in WebScreen. This should fix issue.

Solution

Mofeng Zhang wrote:

Hi team,

I'm currently trying to use an open-source JavaScript library in my OutSystems Web project and those external JavaScript code MUST be added to the end of <body> tag in html.

It seems that if I try to add JavaScript code to my application using the method shown in the picture attached, those code will be inserted into the <head> section automatically.

I have to give up developing on OutSystems if I can't use this JavaScript library so are there any option to put JS code just before the end of <body> section?

Thank you in advance.


Hello Zhang,


You can put your script in the layout section in order to make it work.

I also did it long back that worked for me. below image

 This means all the HTML will be rendered first than this script. just try and let me know if it worked for you.

Regards,

Pankaj


Solution

Pankaj pant wrote:

Mofeng Zhang wrote:

Hi team,

I'm currently trying to use an open-source JavaScript library in my OutSystems Web project and those external JavaScript code MUST be added to the end of <body> tag in html.

It seems that if I try to add JavaScript code to my application using the method shown in the picture attached, those code will be inserted into the <head> section automatically.

I have to give up developing on OutSystems if I can't use this JavaScript library so are there any option to put JS code just before the end of <body> section?

Thank you in advance.


Hello Zhang,


You can put your script in the layout section in order to make it work.

I also did it long back that worked for me. below image

 This means all the HTML will be rendered first than this script. just try and let me know if it worked for you.

Regards,

Pankaj


It worked!

Thanks very much for your help.