Add a script as code - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Script

Description

Add a script as code

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from   ww w.  j a  v  a 2 s .c  o  m*/
var scriptWidget = document.createElement('script');
scriptWidget.type = 'text/javascript';
scriptWidget.src = "http://www.example.com/file.js";
console.log(scriptWidget.outerHTML);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials