View Full Version : Hide the javascript from the view source
knguyen99
12-19-2002, 07:51 PM
How do I hide my javascript from html page (from view source on right click)?
Philip M
12-19-2002, 07:54 PM
Here we go again!
You don't. It cannot be done. In any case, why do you want to do this?
There are ways of disguising your code, but Whammy will crack it within a few seconds!
Skyzyx
12-20-2002, 02:01 AM
Can someone please make the below link a sticky? It talks about protecting your page's source, including debate on whether it's even possible:
http://www.codingforums.com/showthread.php?s=&threadid=4437
Admin note- Thread edited for provocative content. Please simply PM me in the future if you have concerns regarding a specific thread, and I'll handle it.
whammy
12-20-2002, 02:09 AM
P.S. Mr. Nguyen... he's right - you can't hide source code, it's impossible.
If you need to hide your validation from prying eyes, you must use a server-side language so the validation is not sent to the client's browser.
Source code is completely and totally open to the world. :)
P.S. Thanks for your vote of confidence, Philip M - I probably COULD crack it fairly quickly, but I'm nowhere NEAR the guru that some of the people on this forum are - I would name them but then I'd have to kill you. LOL just kidding. ;)
Skyzyx
12-20-2002, 02:14 AM
Fair enough. knguyen99, please take my comments, exclude the rudeness. I apologize.
All I'm saying is that I think that Mr. George "WA" should write something up, make it a sticky, and that should reduce the number of these threads popping up. That's all.
whammy
12-20-2002, 02:23 AM
I think there IS a sticky thread regarding this (I may be mistaken), but you do have to realize that people will be asking these questions as soon as they realize they can do something "cool" using javascript, and aren't really familiar with the way everything works.
I used to get a little peeved at these kinds of questions myself, and then I realized what I said above, and what I thought when I was at that stage in web development/programming. I think we just need to explain how it works and go from there. :D
Skyzyx
12-20-2002, 02:32 AM
Whammy... there is, but it's in the General Web Building forum.
whammy
12-20-2002, 02:36 AM
Ahh... see the thing is, we've gone over this (as a forum!) countless times before, and suggested things like having new people read over "source code" basics, etc. ad nauseum, before they are allowed to post, etc.
From my experience though, no matter what you try and make people read, etc., these kinds of questions will always be asked. You just have to live with it, and don't ever forget to think back to when you were an internet/web development newbie yourself. :D
I guess that's all I have to say. Let's let this be, and state for the record (for Mr. Nguyen's benefit) that you cannot hide source code. :)
<script language="JavaScript" src="jscript source file.js">
Then your scripts will not be visible in your html source code. Same concept as a CSS.
Tanker
12-20-2002, 05:35 PM
But the <script language="JavaScript" src="jscript source file.js"> will be visible in the source, which means you just need to point the browser at that location and theres your script. :(
Roy Sinclair
12-20-2002, 06:41 PM
I was trying not to get involved in yet another discussion but I think a point needs to be made here. In order for the browser to be able to render content and run the javascript both the HTML and the JAVASCRIPT on every page have to be presented to the browser in a form that the browser can read. The one and only form the browser accepts is text, the same text that your own eyes can read.
It's possible to make it hard to read (remove all whitespace, obscure variable names) but it cannot be made impossible to read since the browser needs to be able to read it too!.
cvsouth
05-09-2010, 07:24 PM
Can you not load your javascript dynamically using php?
Iv not tried, its just an idea:
<script language="JavaScript" src="LoadScript.php">
Philip M
05-09-2010, 07:29 PM
Can you not load your javascript dynamically using php?
Iv not tried, its just an idea:
<script language="JavaScript" src="LoadScript.php">
No. How can a php.file be Javascript?
Here we go again!
You don't. It cannot be done. In any case, why do you want to do this?
There are ways of disguising your code, but Whammy will crack it within a few seconds!
TinyScript
05-09-2010, 07:41 PM
you can make it harder for noobs to find if you give the js file a jpg extension
then call the script like
<script src="scriptname.jpg"></script>
It'll look like a mistake, at first glance, so you can make your page have a really elaborate dummy script that does nothing and have the script that looks like it's a mistake be the one that runs the page.
LOL
That's the best I can do!
Philip M
05-09-2010, 08:48 PM
See Post #10. But I agree it might fool a noob. For a few minutes. Any extension including .php seems to work. But the file content is of course JavaScript, not php.
Old Pedant
05-09-2010, 09:12 PM
Sure, the extension on the URL can be anything.
And you can even generate the JS code dynamically. Example:
<script src="foo.php?b=17&a=xyz"></script>
vs.
<script src="foo.php?b=33&a=zam"></script>
And even though it's the same php (or asp or jsp or cgi or whatever) page, the generated JS code can be completely different, based on the passed parameters.
But, as you keep saying Philip, it's *STILL* going to have to be plain old ordinary text or the browser won't be able to process it as script. So I don't see how this is any different than <srcipt src="imageOfBigBen.gif"> in the sense that it won't fool anybody but a rank newbie.
You know, the really silly part, to me, is that people who ask this question are always newbies. And, as newbies, why do they think that they will be creating any JS content that anybody would *want* to steal? Shoot, if you want to hide what your code is really doing, just use jQuery. <snicker />
TinyScript
05-09-2010, 10:49 PM
Shoot, if you want to hide what your code is really doing, just use jQuery. <snicker />
LOL
he could try $.hide("MyNoobCode")
NicMartel
08-12-2011, 08:26 AM
WILL YA!!!!! STOPPP!!!!!!
IT CAN NOT BE DONE !!!
Here is a good example of all the LIES on the Internet about hiding javascript code/client code/HTML/...
They claim your code can be hidden and is safe!!!!
http://www.portaldepot.net/articles/HideCode.html
...with just the Google Browser I was able to print out all their code in less than a few clicks...
no Whammy needed LOL.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.