1.检测iframes的嵌套方式一
if (self.frameElement && self.frameElement.tagName == "IFRAME") {alert(‘在iframe中’);
}
2.检测iframes的嵌套方式二
if (window.frames.length != parent.frames.length) {alert(‘在iframe中’);
}
3.检测iframes的嵌套方式三
if (self != top) {alert(‘在iframe中’);
}
1.禁止页面被别人iframe嵌套方法一
<script language="javascript">
if (top.location != location)
{
top.location.href = location.href;
}
</script> //或
<script language="javascript">
if(self!=top){top.location.href=self.location.href;}
</script>
破解:
<iframe src="你的页面地址" name="tv" marginwidth="0" marginheight="0" scrolling="No" noResize frameborder="0" id="tv" framespacing="0" width="580" height="550" VSPACE=-145 HSPACE=-385></iframe>
<script language="javascript">
var location="";
var navigate="";
frames[0].location.href="";
</script>
2.禁止页面被别人iframe嵌套方法二
<script language="javascript">
if(top != self){ location.href = "about:blank"; //也可设置为你自己的URL
}
</script>
破解:
<script language="JavaScript">
try{top.location.hostname;if (top.location.hostname != window.location.hostname) {top.location.href =window.location.href;}
}
catch(e){top.location.href = window.location.href;
}
</script>
iframe 子页面点击事件,父页面触发的方法
window.frames["我是iframe的id"].window.click(function (event){
}