Sunday, March 1, 2009

Loading External Javascript Files

Static:
<script src="/includes/scripts/test.js" type="text/javascript"></script>

Dynamically Static Way:
<script type="text/javascript">
function staticLoadScript(url)
{
document.write('<script src="', url, '" type="text/JavaScript"><\/script>');
}
staticLoadScript("/includes/scripts/test.js");
</script>

Dynamically DHTML Way:
<script type="text/javascript">
function dhtmlLoadScript(url)
{
var e = document.createElement("script");
e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);
}
onload = function()
{
dhtmlLoadScript("/includes/scripts/test.js");
}
</script>

Reference: http://www.ecma-international.org/publications/standards/Ecma-262.htm

No comments:

Post a Comment