2013-01-22 24 views
0

我有一个弹出窗口,它将从网格中搜索项目。当直接选择一行时,它将值返回到父页面。但是,如果我通过按钮单击搜索网格并选择一行,父页面会收到未定义的对象,但从弹出窗口返回正确的值。父页面如何接收正确的值?回发后modaldialog的返回值

+0

我只是发现了它在IE浏览器,但这个概率罚款发生在chrome – JaseemAmeer

+0

我认为你的意思是ASP.NET?请显示你如何做模态。 –

+0

http://stackoverflow.com/questions/10213530/javascript-showmodaldialog-not-returning-value-in-chrome 这一个为我工作 – JaseemAmeer

回答

0

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();