adsense

Friday, March 29, 2024

Append JavaScript to html body

      

Following JavaScript code will append an external JavaScript file to the document body. This can be used as guide to load a JavaScript file on the fly.

<script type="text/javascript">

var newScript = document.createElement('script');

newScript.type = 'text/javascript';

 newScript.async = true;

 newScript.src = 'https://somedomain.com/JsFileName.js'; 

document.getElementsByTagName("body")[0].appendChild(newScript);

 </script>

cheers,

Samitha

No comments:

Post a Comment