Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Simple JS Include function (See related posts)

// Simple JS Include function... add a root.js to the base lib directory...

function $include(path)
{
var x, base, src = "root.js", scripts = document.getElementsByTagName("script");
for (x=0; x<scripts.length; x++){if (scripts[x].src.match(src)){ base = scripts[x].src.replace(src, "");break;}}
document.write("<" + "script src=\"" + base + path + "\"></" + "script>");
}

Comments on this post

seant23 posts on Jul 11, 2007 at 13:27
The problem with they way your using it that the included script won't get parsed untill the current script is finished being parsed. here is a better solution for realtime inclusion.

http://www.exit12.org/archives/12

You need to create an account or log in to post comments to this site.


Click here to browse all 5146 code snippets

Related Posts