gpt4 book ai didi

Javascript 域保护脚本

转载 作者:行者123 更新时间:2023-11-28 08:38:20 25 4
gpt4 key购买 nike

我制作了一个 .js 文件,我想稍微保护一下它。光是小水蛭,显然更高级的人就能弄清楚。

我想在我的脚本中添加一些内容来检查文件正在哪个域上运行。如果不是我的两个域(example1.comexample2.com),它将重定向到我的域。有点像 iframe 破坏者。

然后我可以获取整个代码并对其进行一些混淆。我的目的是防止有人下载 .js 并在他们的服务器上使用它。

我的代码:

if(typeof(width)=='undefined')width=655;
if(typeof(height)=='undefined')height=540;
if(width<655)width=655;if(height<540)height=540;
if(width<height)height=width;
document.write('<ifr'+'ame src="/streams/hd/'+ ch+'.php" scrolling=no frameborder=0 width='+ width+' height='+ height+' scrolling=no allowtransparency=true id=thatframe ></ifr'+'ame>');

我可以添加一些东西来只允许脚本在我的网站上运行吗? example1.comexample2.com

最佳答案

使用返回主机名的document.location.host,然后 checkin 您的脚本,例如

var _host = document.location.host;
if( _host == "example1.com" || _host == "example2.com" ){
// do things for example1.com
}

如果你想保护你的JS文件,那么使用jscompress压缩版本。

关于Javascript 域保护脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20811350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com