JS模態視窗傳回值相容問題解決方案

來源:互聯網
上載者:User

標籤:

因系統要相容原IE已使用的關閉方法,經調試測得,需對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;");
<span style="color:#ff0000"> if (typeof (ret) == "undefined") {
ret = window.ReturnValue;
}</span>
if (ret) {
document.getElementById("hidDeptCode2").value = ret;
document.getElementById("btnDeptCodeAdd").click();
}
return false;
}

 

-----------------------------------------------------------------------------------------------------------------------

 

1、開啟快顯視窗時把 window 作為第二個參數傳入。

 var result = window.showModalDialog(url, window, "dialogWidth=" + width + "px;dialogHeight=" + height + "px;resizable:yes;")

 if (typeof (result) == ‘undefined‘) {

         result = window.ReturnValue;

     }

     return result;

2、在快顯視窗中,執行如下JS,以接收傳入的window

 if (typeof (window.opener) == ‘undefined‘) window.opener = window.dialogArguments;

 

3、快顯視窗關閉前,調用如下JS賦傳回值

 window.retureValue = vals;

        if (window.opener && window.opener != null)

                window.opener.ReturnValue = vals;

 

        window.close();

 


部落格園davidyang78原創,轉載請保留此資訊

 

 

 

原理探討:

 

chrome下,標準方法,在彈出頁面不回傳的情況下,是可以傳回值的。 有回傳則不能正常傳回值。此方法可以解決。

 

IE下標準方法,有時不明原因不能正確傳回值,此方法可解決。

 

FF未詳細測試,應該問題不大。

JS模態視窗傳回值相容問題解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.