Unload Javascript Files





12
Date Submitted Wed. Nov. 15th, 2006 7:29 AM
Revision 1 of 1
Scripter Casper42
Tags JavaScript
Comments 2 comments
I found this to be a neat little trick for hiding(somewhat) source javacscript code from peering eyes...

This function will unload all linked javascript files so that when you view source - you see no javascript files! (Especially helpful when using FF and using web-developer tools - no linked js files are displayed) The files remain resident in memory - allowing for the functions to work.

Just call the function in the tag

function unloadJS(scriptName) {
  var head = document.getElementsByTagName('head').item(0);
  var js = document.getElementById(scriptName);
  js.parentNode.removeChild(js);
}

function unloadAllJS() {
  var jsArray = new Array();
  jsArray = document.getElementsByTagName('script');
  for (i = 0; i < jsArray.length; i){
    if (jsArray[i].id){
      unloadJS(jsArray[i].id)
    }else{
      jsArray[i].parentNode.removeChild(jsArray[i]);
    }
  }       
}
 

Jeremy Edmiston

Comments

Comments cant work ???
Sat. Sep. 22nd, 2007 7:36 AM    Helper el_nokio
Comments not working
Mon. Dec. 18th, 2006 5:40 AM    Syntax Master sundaramkumar

Voting