Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript file for single domain

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 :)

like image 797
HasanG Avatar asked Jul 30 '26 06:07

HasanG


2 Answers

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.

like image 69
Sarfraz Avatar answered Aug 01 '26 19:08

Sarfraz


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.

like image 39
T.J. Crowder Avatar answered Aug 01 '26 19:08

T.J. Crowder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!