被嵌套到iframe里面强制跳转方法,防止强制跳转方法

<script>
    if(top.location!=self.location){top.location=self.location}
</script>

自动判断当前的location是否是顶层的,即是否被嵌套到iframe里面了,如果是,则强制跳转。

 

防止强制跳转方法:即增加两个:security="restricted" sandbox="",前者是IE的禁止js的功能,后者是HTML5的功能。刚好就可以让IE,Chrome,Firefox这三大浏览器都实现了禁止iframe的自动跳转。但这样iframe里面的所有js也不能用了。

	<iframe security="restricted" sandbox="" id="baiyug" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" allowfullscreen="true" src="<?php echo "http://wjsou.com:8080/s2.jsp?q=".$_GET['q']; ?>" height="1000px" width="100%"></iframe>

 

sandbox 属性

 

"" 应用以下所有的限制。
allow-same-origin 允许 iframe 内容被视为与包含文档有相同的来源。
allow-top-navigation 允许 iframe 内容从包含文档导航(加载)内容。
allow-forms 允许表单提交。
allow-scripts 允许脚本执行。

其它方法:https://blog.csdn.net/dugujiancheng/article/details/51669164

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值