当一个窗口被嵌套在很多iframe或window.showModalDialog者中,用这个方法找到顶窗口(前提是window.showModalDialog的前一
个窗口传了window对象)
var w;
function get_main_ui_w() {
if (w == undefined) {
w = window;
}
//模态
if (w.dialogArguments != undefined) {
w = w.dialogArguments;
//判断是否是主窗口
//传的对象中,属性win也是window对象
if (w.document == undefined) {
w = w.win;
if (w.document.getElementById("Corp_ID") != null) {
//是,返回
main_ui_w = w;
return ;
} else {
//否,迭代
get_main_ui_w();
} // end of if (w.document.getElementById("Corp_ID") == null)
} else {
if (w.document.getElementById("Corp_ID") != null) {
//是,返回
main_ui_w = w;
return w;
} else {
//否,迭代
get_main_ui_w();
} // end of if (w.document.getElementById("Corp_ID") == null)
}
}
//iframe
else {
w = w.parent;
//判断是否是主窗口
if (w.document.getElementById("Corp_ID") != null) {
//是,返回
main_ui_w = w;
return;
} else {
//否,迭代
get_main_ui_w();
} // end of if (w.document.getElementById("Corp_ID") == null)
}
// end of if (window.dialogArguments != undefined)
}