页面层级如下
top:www.a.com/index.html
----------------- iframe:www.b.com/page1.html-------------------
----------------- iframe: www.b.com/page2.html-------------------
//此页面访问 window.top 时会指向 www.a.com/index.html 页面,触发浏览器跨域安全异常
----------------- end iframe----------------------------------------------
----------------- iframe----------------------------------------------
在b系统中的通用启动脚本开头加入以下代码
/* 将window.top 和 window.parent 指向当前域下顶层页面 */
(function(){
var cwin = window;
while(cwin != cwin.parent){
try{
var href = window.parent.location.href;
cwin=cwin.parent;
}catch(ex){
break;
}
}
window.top = window.topWindow = cwin;
try{
var href = window.parent.location.href;
window.parentWindow = window.parent;
}catch(ex){
window.parent = window.parentWindow = window;
}
})()