单个域的 Javascript 文件 [英] Javascript file for single domain

查看:29
本文介绍了单个域的 Javascript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使 javascript 文件仅适用于单个域.我会压缩这个文件,当有人试图通过复制我的网站或仅复制 javascript 文件来使用它时,它不会工作并发出警报.

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:

if (window.location.href.substring(0, 18) != "http://example.com") {
    alert("You thief! Stop using my code!");
}

...但这意味着使用它的人会从他们的副本中删除它.混淆 可能会有所帮助,但不一定有用.Javascript 解释器可以解释的任何东西,有人可以复制和重用.您所能做的就是将标准设置得更高一些,您可能还有更重要的事情要做.

...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.

这篇关于单个域的 Javascript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆