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 :)
That's not possible, javascript can be obfuscated but an adept developer can always figure that out and use your files. You can copyright your file but still in countries where there is no privacy policies, this won't matter.
You can't really do this. You could put something at the beginning of your code like this:
if (window.location.href.substring(0, 18) != "http://example.com") {
alert("You thief! Stop using my code!");
}
...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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With