了解window.top

 当B嵌套在A页面中时,直接是不能调用A页面的方法和属性的

如果想使用A页面中的方法和属性 可以使用window.top (返回窗口层级最顶层窗口的引用)

if(window.top != window.self) {
  window.top.location.href = window.location.href;
window.top.oepn = window.open }

当在iframe内时, 直接window.location.href 会打开iframe内的网站,  要解决这个问题 使用window.top.location.href = xxx 或者 window.top.open('xxx')

原文地址:https://www.cnblogs.com/it-Ren/p/13903366.html