关于iframes的嵌套问题

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){
}
  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值