惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
S
SegmentFault 最新的问题
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
M
MIT News - Artificial intelligence
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
B
Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
C
Cybersecurity and Infrastructure Security Agency CISA
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
U
Unit 42
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Cloudflare Blog
H
Help Net Security
Recent Announcements
Recent Announcements
P
Privacy & Cybersecurity Law Blog
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 热门话题
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
H
Heimdal Security Blog
博客园 - 聂微东
S
Securelist
大猫的无限游戏
大猫的无限游戏
Cloudbric
Cloudbric
Cisco Talos Blog
Cisco Talos Blog

拓源网

微信和QQ访问页面提示使用右上角浏览器打开 - 拓源网 [反调试]审查元素清空页面或重定向 - 拓源网 批量替换文件名的powershell脚本 - 拓源网 使用Python移除PDF编辑权限密码 - 拓源网 写一款《PPT将指定页面另存为》小工具 - 拓源网 PPT拼图批量生成工具 - 拓源网 Deepseek微信聊天机器人 - 拓源网 使用Python自动抓取zblog文章到腾讯云大模型知识引擎LKE,投喂数据专属化自己的知识库 - 拓源网 deepseek生图指令 - 拓源网
让jquery代码只能在指定域名下运行的三种方法 - 拓源网
2025-05-18 · via 拓源网

Base64方法一:

对整个字符串进行Base64编码,要确保在编码和解码过程中,域名列表始终是有效的JSON格式。这样可以避免JSON.parse()抛出语法错误。

const encodedDomains = 'WyJsb2NhbGhvc3QiLCIxMjcuMC4wLjEiXQ==';//localhost、127.0.0.1
const decodedDomainList = JSON.parse(atob(encodedDomains));
const currentDomain = window.location.hostname;
if (decodedDomainList.includes(currentDomain)) {
    $(function(){
        //jQuery代码段...
        $('body').append('<p>看到此内容代表在允许的域名中且运行完毕</p>');
    });
}

Base64方法二:

对单独的域名进行Base64编码。

var allowedDomains = ['bG9jYWxob3N0','MTI3LjAuMC4x']; //localhost, 127.0.0.1
var currentDomain = window.location.hostname;
var isAllowed = false;

for (var i = 0; i < allowedDomains.length; i++) {
    var decodedDomain = atob(allowedDomains[i]);
    if (currentDomain.endsWith(decodedDomain)) {
        isAllowed = true;
        break;
    }
}
if (isAllowed) {
    $(function(){
        //jQuery代码段...
        $('body').append('<p>看到此内容代表在允许的域名中且运行完毕</p>');
    });
}

16进制方法:

const hexEncodedDomains = '5b226c6f63616c686f7374222c223132372e302e302e31225d';//localhost、127.0.0.1
const hexToArray = hexEncodedDomains.match(/.{1,2}/g);
const decodedDomainList = String.fromCharCode(...hexToArray.map(byte => parseInt(byte, 16)));
const domainList = JSON.parse(decodedDomainList);
const currentDomain = window.location.hostname;
if (domainList.includes(currentDomain)) {
    $(function(){
        //jQuery代码段...
        $('body').append('<p>看到此内容代表在允许的域名中且运行完毕</p>');
    });
}

以上三种方法均以localhost和127.0.0.1为例,无论是Base64还是16进制法,都可被轻易的解码,可使用更复杂的AES算法。