The best magazine
Adding Javascript Dynamically With DOM Scripting
- 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: ...