How to prevent javascript linking
I'm serving a javascript file from my server. How do I prevent direct linking to it so that the server doesn't get used to serve the javas开发者_Go百科cript to other websites?
The usual techniques for blocking hotlinking apply.
To discourage hotlinking you could put annoying code in the script and have that execute if window.location
doesn't match your own site:
while (window.location.hostname !== 'www.example.com')
alert('Plz stop hotlinking');
There is no good way to do so. However, you could do some referer checks or check the values from the location
object and make the JavaScript do bad things when embedded from a different site.
When doing referer checks don't forget to allow an empty referer as some people block referers.
精彩评论