Skip to content

Instantly share code, notes, and snippets.

@jasdeepkhalsa
Created November 29, 2012 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdeepkhalsa/4168703 to your computer and use it in GitHub Desktop.
Save jasdeepkhalsa/4168703 to your computer and use it in GitHub Desktop.
JavaScript include()
// From http://xkr.us/
/** include - including .js files from JS - bfults@gmail.com - 2005-02-09 **
** Code licensed under Creative Commons Attribution-ShareAlike License **
** http://creativecommons.org/licenses/by-sa/2.0/ **/
var hIncludes = null;
function include(sURI)
{
if (document.getElementsByTagName)
{
if (!hIncludes)
{
hIncludes = {};
var cScripts = document.getElementsByTagName("script");
for (var i=0,len=cScripts.length; i < len; i++)
if (cScripts[i].src) hIncludes[cScripts[i].src] = true;
}
if (!hIncludes[sURI])
{
var oNew = document.createElement("script");
oNew.type = "text/javascript";
oNew.src = sURI;
hIncludes[sURI]=true;
document.getElementsByTagName("head")[0].appendChild(oNew);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment