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

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.


Capture.PNG

Champion
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


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.


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.

Durgesh Rokade wrote:

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.

 This approach worked for me. but instead of using window.onload i added the direct function code as a javacript code under onRender screen method for my reactive web app.

 

Champion
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


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.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.