0
我有一個彈出窗口,它將從網格中搜索項目。當直接選擇一行時,它將值返回到父頁面。但是,如果我通過按鈕單擊搜索網格並選擇一行,父頁面會收到未定義的對象,但從彈出窗口返回正確的值。父頁面如何接收正確的值?回發後modaldialog的返回值
我有一個彈出窗口,它將從網格中搜索項目。當直接選擇一行時,它將值返回到父頁面。但是,如果我通過按鈕單擊搜索網格並選擇一行,父頁面會收到未定義的對象,但從彈出窗口返回正確的值。父頁面如何接收正確的值?回發後modaldialog的返回值
OP在這個問題的評論中提到了這一點,但要說清楚:這個答案是用戶ConnorsFan的this one的副本。如果答案已更新,那麼可能會出現更新。
爲了保持我的網頁使用的showModalDialog,我只好拿出我自己的解決方法的錯誤。所以,這裏是...
在Google Chrome瀏覽器中,回傳後,showModalDialog總是返回undefined。但是,模式對話框中的window.opener屬性指向調用者窗口,即使在回發之後。所以,我想將對話框的結果放在該調用者窗口的returnValue屬性中。它的工作原理。
在來電窗口:
var prevReturnValue = window.returnValue; // Save the current returnValue
window.returnValue = undefined;
var dlgReturnValue = window.showModalDialog(...);
if (dlgReturnValue == undefined) // We don't know here if undefined is the real result...
{
// So we take no chance, in case this is the Google Chrome bug
dlgReturnValue = window.returnValue;
}
window.returnValue = prevReturnValue; // Restore the original returnValue
在這一點上,使用dlgReturnValue作進一步處理 在模態對話框窗口:
if (window.opener)
{
window.opener.returnValue = dateValue;
}
window.returnValue = dateValue;
self.close();
我只是發現了它在IE瀏覽器,但這個概率罰款發生在chrome – JaseemAmeer
我認爲你的意思是ASP.NET?請顯示你如何做模態。 –
http://stackoverflow.com/questions/10213530/javascript-showmodaldialog-not-returning-value-in-chrome 這一個爲我工作 – JaseemAmeer