how does this work?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

how does this work?

 
0
  #1
Jan 22nd, 2007
How to set this up?



source
http://www.tutorialized.com/tutorial...sing-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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function unloadJS(scriptName) {
  2. var head = document.getElementsByTagName('head').item(0);
  3. var js = document.getElementById(scriptName);
  4. js.parentNode.removeChild(js);
  5. }
  6.  
  7. function unloadAllJS() {
  8. var jsArray = new Array();
  9. jsArray = document.getElementsByTagName('script');
  10. for (i = 0; i < jsArray.length; i){
  11. if (jsArray[i].id){
  12. unloadJS(jsArray[i].id)
  13. }else{
  14. jsArray[i].parentNode.removeChild(jsArray[i]);
  15. }
  16. }
  17. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 11
Reputation: theonlydrayk is an unknown quantity at this point 
Solved Threads: 0
theonlydrayk's Avatar
theonlydrayk theonlydrayk is offline Offline
Newbie Poster

Re: how does this work?

 
0
  #2
Jan 29th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: how does this work?

 
0
  #3
Feb 2nd, 2007
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.
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: how does this work?

 
0
  #4
Feb 5th, 2007
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <body onload="hideAllJS();">

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <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.
Last edited by MattEvans; Feb 5th, 2007 at 9:24 am.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: how does this work?

 
0
  #5
Feb 5th, 2007
Ah I see. Ok thats simple enough. Was just curious about it. By the way Matt, Thanks Again For help, Really Appreciated!
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: how does this work?

 
0
  #6
Feb 5th, 2007
Still dosent seem to work, javascript still visible via veiw source (i assume this is where it hides it?)
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: how does this work?

 
0
  #7
Feb 5th, 2007
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)
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: how does this work?

 
0
  #8
Feb 5th, 2007
Oh ok, I wondered why it was still visible lol. Bit of a pointless code eh. Oh well nevermind. Thanks again for info Mate!
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC