JavaScript - Security for the code written in script

Asked By Naresh Kumar on 08-Apr-10 02:35 AM
Hi All,

When the users right click on the browser and clicks on ViewSource then the users can see the code written in script. How can I give security for this.

Please its bit urgent any one can help me in this..

Thanks in advance.
Anand Malli replied to Naresh Kumar on 08-Apr-10 02:47 AM
hi there

i can understand what you are trying to say,generally you can not hide anything which is on client side,but with little trick you can easily hide the code or obsfucate it

1) i would suggest you to use minifier as well as obsfucator so it will minimize your script as well as encrypt it

 try searching for this term in google "javascript obfuscator"

2) this is approch is rock solid,use microsoft's tool called DOLOTO,it generated the code on the fly for your javascript and nobody would understand,except DOLOTO :)

happy coding

Naresh Kumar replied to Anand Malli on 08-Apr-10 03:03 AM
Thanks for your quick reply.
DL M replied to Naresh Kumar on 08-Apr-10 03:20 AM
You can try this code sample

<SCRIPT language=JavaScript>
<!-- http://www.spacegun.co.uk -->
    var message = "function disabled";
    function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){     alert(message); return false; }
    if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) {     alert(message);     return false; } }
    document.onmousedown = rtclickcheck;
</SCRIPT>

show here more help full link
http://www.hypergurl.com/norightclick.html
http://www.codeproject.com/KB/aspnet/Disabling_the_right_click.aspx
Sagar P replied to Naresh Kumar on 08-Apr-10 03:26 AM
I don't think there is any way to disable the View Source command. Even the way of disabling the Right Click works if Javascript is enabled.

I feel the best you can do to prevent your source code from being viewed is to obfuscate & compress HTML, CSS & Javascript code. Like GMail, use hidden frames to make viewing the source tougher.

There are many free online compression tools, like these:
http://compressor.ebiene.de/
http://dean.edwards.name/packer/

Compression also has the added benefit of making your pages load faster.

If this does not help, try using a commercial tool like HTML Protector to protect
              the content of your web page -
http://www.antssoft.com/htmlprotector/index.htm

Also check this discussion;
http://www.eggheadcafe.com/community/aspnet/2/10057700/re-url.aspx
Super Man replied to Naresh Kumar on 08-Apr-10 09:02 AM

Its not possible, if you do any trick like disabling right click, but if user can disable javascript,then this tricks can not work.