js 迭代找到父窗口

当一个窗口被嵌套在很多iframe或window.showModalDialog者中,用这个方法找到顶窗口(前提是window.showModalDialog的前一

个窗口传了window对象)//主界面window对象 var main_ui_w = window; //判断FF if (!$.browser.msie) { //判断为模态窗口 if (window.dialogArguments != undefined) { get_main_ui_w(); alert(main_ui_w.document.getElementById("Corp_ID").value); } //end of if (window.dialogArguments != undefined) { } //end of if ($.browser.msie) 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) }

你可能感兴趣的:(UI,function,iframe,null)