How can I make a javascript file only work on a single domain. I’ll compress this file and when somebody tries to use it by copying my web site or just the javascript file, it won’t work and give alert.
Here is an example. I downloaded all files but when try to view it gives an alert that says I need to buy it (what exactly I’m going to do 🙂
You can’t really do this. You could put something at the beginning of your code like this:
…but all that means is that the person using it would remove that from their copy. Obfuscation might help, but not necessarily by much. Anything the Javascript interpreter can interpret, someone can copy and reuse. All you can do is set the bar a bit higher, and you probably have more important things to do.