例如,我有一个名为www.example.com的网站,它是一个父域。我在它里面使用了框架。在框架内部,我调用了www.mail.example.com
我需要检查是否mail.example.com(网址内iframe)是同一域名,谷歌有…
这可以防止跨框架脚本。如何做到这一点?
我算出的情态动词..
if (window.document.domain != top.document.domain) {
SWGuardianWindowOpen("http://google.com","_self","");
}另一个:
if (self != top)
{
//redirect to the google.com
}
if (parent && parent.frames && parent.frames.length>0)但这些都没什么用。
发布于 2014-03-04 23:56:22
如果你想阻止不同来源的页面嵌入你的网站,你不需要JavaScript黑客。
只需将以下标记添加到您的超文本标记语言文档的<head>中(例如:http://jsfiddle.net/b28CK/show/):
<meta http-equiv="X-Frame-Options" content="SAMEORIGIN">如果允许修改服务器的响应头,也可以添加X-Frame-Options: SAMEORIGIN响应头来达到同样的效果。
如果要使用JavaScript检测父源,则可以使用location.ancestorOrigins查找父源的列表。这只适用于Webkit和基于Chromium的浏览器。
https://stackoverflow.com/questions/22176373
复制相似问题