Forum Moderators: open
Alternatively you can render your code very difficult to edit by changing variable names and removing all line breaks.
NB you can't actually stop the script from being saved onto the user's hard disk though or it wouldn't run.
var domainname = location.href;
if (domainname.indexOf("mywebsite.com")>0){
dostuff();
}
2) obfuscate the heck out of the code until it's so unreadable that no one would ever bother stealing it.
People are tired of arguments why it's impossible to "protect" client-side code. And I'm tired of explaining it. Still, sometimes you get birdbrained suits who a) don't understand and b) won't liten, and to appease them try the methods above.
When they see the obfuscated javascript, tell them that it's "encrypted" using a fantastic government algorithm.
Use the word "algorithm" a lot. they like that.
good luck
Removing whitespace, encrypting, etc also has a very beneficial side to it though that has nothing to do with preventing piracy: It makes the file size alot smaller. This is really quite handy if you have a large javascript library.
Dean Edwards's Javascript Packer [I know no URLs, but that should be enough info to hep you find it] can really squash stuff down... often it will reduce the size by over 50%. One note on his packer, I've had some troubles sometimes with the lower encoding settings running in Safari, but it works fantastic on the "High ASCII" setting.