如何阻止iframe里引用的网页自动跳转

canca canca
2018-07-24 13:58
3
0

需求现在在做一个项目,要求一个页面内嵌Bing和Baidu俩个iframe,载入页面后,从url中拿数据进行搜索。

问题完全载入页面后,会跳转到百度页面。

问题来源百度代码中有 

if (top.location != self.location) {top.location=self.location;}


解决办法

<iframe src="" class="iframe" scrolling="no" security="restricted" sandbox="">

即增加两个:security="restricted" sandbox=""(内嵌百度时要允许弹框,即sandbox="allow-popups"),前者是IE的禁止js的功能,后者是HTML5的功能。刚好就可以让IE,Chrome,Firefox这三大浏览器都实现了禁止iframe的自动跳转.

发表评论