iframe实现子页面内跳转到整个页面

9,978 阅读1分钟

问题描述:

页面内嵌iframe时,实现子页面内点击跳转是整个页面的跳转,而不是在子页面内跳转。

问题解决方法:

  • 方法一:

  如果你的页面跳转是使用的<a></a>标签,只需在 a 标签中添加 "target="_parent" 属性即可。

  • 方法二:  

    在head标签之间加入<base target="_parent" /> 。则子页面内的所有跳转默认是父页面一起跳。(注:在子页面的head标签中添加哦)

  • 方法三:

  在js中跳转,window.location.href或者 window.open();因为window这种跳转是没有target属性的,这时,你可以使用:

让父页面跟着一起跳转,即在

window.location.href=url后面加上window.parent.location.href=url;

例如:

window.location.href=http://www.a.html?window.parent.location.href=http://www.a.html;