保护iFrame - 只允许它在一个域上工作 [英] Protecting iFrame - Only allow it to work on one domain

查看:143
本文介绍了保护iFrame - 只允许它在一个域上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我创建的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屋!

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