For some reason, when using a Javascript from an ASP.NET project, Google Chrome will return an empty (“undefined”) returnValue. , and they have yet to fix it.
Fortunately there is a workaround.
First the modal window:
When closing the modal window it is not enough to set the window.returnValue to the specified return value. Instead, check for the and set the returnValue there as well:
1 2 3 4 5 6 7 | <script language= "javascript" type= "text/javascript" > if (window.opener) { window.opener.returnValue = "your return value" ; } window.returnValue = "your return value" ; self.close(); </script> |
Then the window calling the modal window:
To receive the return value from the modal window you need to do this:
1 2 3 4 5 6 7 | window.returnValue = undefined; var result = window.showModalDialog( "modalwindow.aspx" , window, "dialogHeight:650px; dialogWidth:900px;" ); if (result == undefined) result = window.returnValue; if (result != null && result != "undefined" ) // Do something with the return value // defined in "result" |
This has beed tested in IE9 and Google Chrome 21.0.1180.83 m. According to other sources it will work in later Firefox versions as well.
Further reading:
- from StackOverflow
- from Chromium bug report system. 来源: <>