回发后moddialog的返回值
本文关键字:返回值 moddialog | 更新日期: 2023-09-27 17:54:55
我有一个弹出窗口,它将从网格中搜索项目。当直接选择一行时,它将值返回给父页。但是,如果我通过单击按钮搜索网格并选择一行,则父页面会收到未定义对象,尽管弹出窗口会返回正确的值。父页面如何接收正确的值?
OP确实在这个问题的评论中提到了这一点,但是要明确一点:这个答案是ConnorsFan用户的这个答案的副本。如果答案已更新,则可能会出现任何更新。
为了在我的页面中继续使用showModalDialog,我不得不为这个bug想出我自己的解决方案。所以,这里是…
在Google Chrome中,在回发之后,showModalDialog总是返回undefined。然而,窗口。即使在回发之后,模态对话框中的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();