保护iFrame - 只允许它在一个域上工作 [英] Protecting iFrame - Only allow it to work on one domain
问题描述
我有一个我创建的Widget,并使用iFrame将其嵌入到其他网站。我想要做的是确保没有人可以查看源代码并复制iFrame代码并将其放在自己的网站上。
我可以存储它应该的URL被允许在数据库中。我以前看过它,一个网站有一个很长的加密代码,如果它与域不匹配,那么它会说访问被拒绝。
有谁知道我该怎么做?
谢谢!
if(window.top.location.host!=hostname){
document.body.innerHTML =访问被拒绝;
}
将上述内容添加到JavaScript中,然后使用 JavaSript混淆器
I have a Widget that I created and I am embedding it on other websites using an iFrame. What I want to do is make sure no one can view the source and copy the iFrame code and put it on their own website.
I can store the URL that it should be allowed on in the database. I've seen it done before, one site had a long encrypted code and if it didn't match with the domain then it said Access Denied..
Does anyone know how I can do this?
Thanks!
No you can't do this. The best thing you can do is the following:
if (window.top.location.host != "hostname") {
document.body.innerHTML = "Access Denied";
}
Add the above to your JavaScript and then use a JavaSript obfuscator
这篇关于保护iFrame - 只允许它在一个域上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!