How to set this up?

source
http://www.tutorialized.com/tutorial/Resizing-An-Image-Using-PHP/16806

Unload Javascript Files

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]);
    }
  }        
}

Nice :)
How to use it ? just put the javascript in your page...


Don't work if you have firefox noscript extension, and blocking all javascript....turn off javascript and you will see the code.

I meant does it go in Body, or Head? just with script tags? It dosent seem to do anything. Javascript is still visible via veiw source.

you will have to add to the body onload event to call that function.

put the code within a script tag in the head section and change the opening body tag to say:

<body onload="hideAllJS();">

if you've allready got some functions called in body onload; do this:

<body onload="exampleFunction1(); exampleFunction2(); exampleFunctionETC();  hideAllJS();">

calling that function from any place other than body onload (which is called supposadly 'after' all loading has occured) may either have a detrimental effect on JS functions within a page; or fail to remove certain blocks.

Ah I see. Ok thats simple enough. Was just curious about it. By the way Matt, Thanks Again For help, Really Appreciated! :D

Still dosent seem to work, javascript still visible via veiw source (i assume this is where it hides it?)

Sorry; the function name there is unloadAllJS not hideAllJS...

But..

It actually wont hide JS from the View Source in most browsers, Most browsers display the source code of the HTML page exactly as it was received (that is, irrespective of what Javascript subsequently does to the page)

The only thing it will hide is the display of Javascript elements in live DOM explorers like that which comes with Firefox... If you really want to hide JS functions; you should put them all in linked .js files and use the same kind of hotlink protection you would for images (conditional redirection at the server)

Oh ok, I wondered why it was still visible lol. Bit of a pointless code eh. Oh well nevermind. Thanks again for info Mate! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.