Faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 89 people (49%) answered Yes
Recently 4 of 10 people (40%) answered Yes


How to prevent user from viewing the source code using browser (view->source)
How to prevent user from viewing the source code using browser (view->source)
How to prevent user from viewing the source code using browser (view->source)

Apr 5th, 2008 20:26
ha mo, Yuriy Fuksenko, Juergen Thelen, Truey Truey,

You cannot prevent that a user views your source code by using the 
appropriate menu functions of his/her browser.
HTML/JavaScript/JScript/VBScript are interpreted languages, no binaries 
(machine language executables). Interpreted languages have to be parsed 
at runtime, i.e. the browser must be able to read and analyze your 
source code on-the-fly, and that's only possible, if the file follows 
the syntax of the appropriate language...
Because interpreted languages usually are not encrypted or scrambled 
(and HTML, JavaScript and stuff weren't thought to be), almost every 
browser offers a function to the user, that allows to view the source.
This is browser internal behaviour, that you usually cannot control or 
influence without explicit consent of the user (using signed scripts or 
active-x controls for example)...
What you can do, is to encrypt/scramble your source with a built-in 
crypt engine, but even that has some disadvantages. Encryption will 
always make your files bigger and slower than plain source, due to the 
overhead needed to decrypt the file afterwards (at runtime). If you 
don't mind this have a look at: 
There you will find some encrypters/scramblers...
If you want to hide your source because its confidential stuff, I would 
rather recommend to relocate the whole stuff to server side, but to use 
client side encryptors/scramblers.
A last word: even if encrypting will prevent many users from viewing 
your source, you should clearly keep in mind, that any sophisticated 
programmer (err, hacker) will always get your source, if he/she really 
wants to. That's the way it is...
Hth, Juergen
There is a related topic: