JS模態(tài)窗口返回值兼容問題的完美解決方法
因系統(tǒng)要兼容原IE已使用的關(guān)閉方法,經(jīng)調(diào)試測(cè)得,需對(duì)window.dialogArguments進(jìn)行再較驗(yàn),不然易出問題。
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的接收模式下,多較驗(yàn)一下opener就可以了,如下:
//選擇變更部門 function SetOrganizeTree2() { var url="彈出頁(yè)面"; 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、打開彈出窗口時(shí)把 window 作為第二個(gè)參數(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下,標(biāo)準(zhǔn)方法,在彈出頁(yè)面不回發(fā)的情況下,是可以返回值的。 有回發(fā)則不能正常返回值。此方法可以解決。
IE下標(biāo)準(zhǔn)方法,有時(shí)不明原因不能正確返回值,此方法可解決。
FF未詳細(xì)測(cè)試,應(yīng)該問題不大。
以上這篇JS模態(tài)窗口返回值兼容問題的完美解決方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
webpack.DefinePlugin與cross-env區(qū)別詳解
這篇文章主要介紹了webpack.DefinePlugin與cross-env區(qū)別詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02HTML中setCapture、releaseCapture 使用方法淺析
本文給大家簡(jiǎn)單介紹了下html中的高級(jí)拖動(dòng)技術(shù)setCapture、releaseCapture的使用方法,有需要的小伙伴可以參考下2016-09-09JavaScript?getter?setter金字塔???????
這篇文章主要介紹了JavaScript?getter?setter金字塔???????,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08JS中將blob返回值轉(zhuǎn)換為json格式的問題小結(jié)
這篇文章主要介紹了JS中如何將blob返回值轉(zhuǎn)換為json格式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-12-12D3.js實(shí)現(xiàn)簡(jiǎn)潔實(shí)用的動(dòng)態(tài)儀表盤的示例
本篇文章主要介紹了D3.js實(shí)現(xiàn)簡(jiǎn)潔實(shí)用的動(dòng)態(tài)儀表盤的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04微信小程序?qū)崿F(xiàn)計(jì)時(shí)器開始和結(jié)束功能
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)計(jì)時(shí)器開始和結(jié)束功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07