Ultimate Sidebar

Adding Javascript Dynamically With DOM Scripting

104 44
    • 1). Copy and paste the following code into the head of your HTML document:
      <script type="text/javascript">
      function dynamic_load(script_url)
      {
      var dynamic_script = document.createElement('script');
      dynamic_script.setAttribute("type","text/javascript");
      dynamic_script.setAttribute("crc",script_url);
      document.getElementsByTagName("head")[0].appendChild(dynamic_script);
      }
      </script>

    • 2). Copy and paste the following code into the body of your HTML document:
      <a onclick="dynamic_load("MyScript.js")">Load MyScript.js</a>

    • 3). Open your HTML document in a browser and click the link from Step 2. The contents of MyScript.js will load as soon as you do.

Source: ...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.