Forum Moderators: open

Message Too Old, No Replies

How to protect JavaScript Code

How to protect JavaScript Code

         

snmrafik

5:47 pm on Apr 15, 2005 (gmt 0)



hello

i am new to javascript

pl help me how to protect my js code

regards

Reboot

10:00 pm on Apr 15, 2005 (gmt 0)



From who protect?
:-)

txbakers

10:19 pm on Apr 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



microsoft has a feww script encoder which works well, but it's not the best algorithim. In fact, there are plenty of free decoders available, but it does slow down the "common" thief.

Bernard Marx

2:38 pm on Apr 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i am new to javascript

What code, in that case, do you have that is worth hiding?

cmatcme

8:53 am on Apr 17, 2005 (gmt 0)

10+ Year Member



Protect from the common thief?

Well, you could create a long list of .js files:

In your document:

 <script>
document.write("<scr" + "ipt " + " sr" + "c=\"bo" + "b.js\"" + "> </script>");
</script>

And in bob.js put another long line of compucated code linking to another .js file etc until you reach the js document reaching the javascript code. Alas the thief could just link to bob.js but just put credits in. He gets the code, you get advertising!

Alternatively block the right click - place this in the head tag:


<script>

<!-- var debug = true;

function right(e) {

if (navigator.appName == 'Netscape' && (e.which == 3 ¦¦ e.which == 2)) return false;

else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 ¦¦ event.button == 3)) {

alert('Why are you bothering?');

return false;

}

return true;
}
document.onmousedown=right;

if (document.layers) window.captureEvents(Event.mousedown);

window.onmousedown=right;

//-->

</script>

Well there you go!

cmatcme

cmatcme

11:13 am on Apr 17, 2005 (gmt 0)

10+ Year Member



Whoops, I don't think that block right click script works. This does though:

<script language="javascript">

<!--

function rightguard() {

if (event.button==2) {

alert('Do not bother')

}

}

document.onmousedown=rightguard

//-->

</script>

Place that in the head tag. You can change alert() to another command like confirm().

Click here for more scripts [google.com]

Sorry!

cmatcme