JS模態(tài)窗口返回值兼容問題的完美解決方法
因系統(tǒng)要兼容原IE已使用的關(guān)閉方法,經(jīng)調(diào)試測得,需對window.dialogArguments進行再較驗,不然易出問題。
function OKEnd(vals) {
if (vals == null) vals = "TRUE";
if (typeof (window.opener) == "undefined") {
if (typeof (window.dialogArguments) != "undefined") {
if (window.dialogArguments && window.dialogArguments != null) {
window.opener = window.dialogArguments;
if (window.opener && window.opener != null) {
window.opener.ReturnValue = vals;
}
}
}
}
else {
if (window.opener && window.opener != null) {
window.opener.ReturnValue = vals;
}
}
window.returnValue = vals;
self.close();
}
返回值接收的,只需在原有IE的接收模式下,多較驗一下opener就可以了,如下:
//選擇變更部門
function SetOrganizeTree2() { var url="彈出頁面";
var ret = window.showModalDialog(url, window, "dialogWidth=400px;dialogHeight=500px;status=no;help=no;scroll=yes;resizable=yes;");
if (typeof (ret) == "undefined") {
ret = window.ReturnValue;
}
if (ret) {
document.getElementById("hidDeptCode2").value = ret;
document.getElementById("btnDeptCodeAdd").click();
}
return false;
}
JS模態(tài)窗口返回值兼容問題完美解決方法
1、打開彈出窗口時把 window 作為第二個參數(shù)傳入。
var result = window.showModalDialog(url, window, "dialogWidth=" + width + "px;dialogHeight=" + height + "px;resizable:yes;")
if (typeof (result) == 'undefined') {
result = window.ReturnValue;
}
return result;
2、在彈出窗口中,執(zhí)行如下JS,以接收傳入的window
if (typeof (window.opener) == 'undefined') window.opener = window.dialogArguments;
3、彈出窗口關(guān)閉前,調(diào)用如下JS賦返回值
window.retureValue = vals;
if (window.opener && window.opener != null)
window.opener.ReturnValue = vals;
window.close();
原理探討:
chrome下,標準方法,在彈出頁面不回發(fā)的情況下,是可以返回值的。 有回發(fā)則不能正常返回值。此方法可以解決。
IE下標準方法,有時不明原因不能正確返回值,此方法可解決。
FF未詳細測試,應(yīng)該問題不大。
以上這篇JS模態(tài)窗口返回值兼容問題的完美解決方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實現(xiàn)網(wǎng)頁截圖功能
這篇文章主要介紹了JavaScript實現(xiàn)網(wǎng)頁截圖功能,本文介紹了2款實現(xiàn)JavaScript截圖的開源組件,一個是Canvas2Image,一個是html2canvas,需要的朋友可以參考下2014-10-10
JavaScript對象和字串之間的轉(zhuǎn)換實例探討
從對象的格式可以看出,如果字串的格式定義成 json 格式的, 就可以直接轉(zhuǎn)換為obj了,感興趣的朋友可以參考下哈2013-04-04

