What to do when returnValue of modal window always returns undefined in Internet Explorer?
Sunday, May 17, 2009 11:43:10 AM
Today I was fighting with IE8 for a few hours because this stupid browser enjoys torturing web-developers. There is a method in JavaScript in IE called window.showModalDialog which opens modal popup. This method returns value which was set by page opened in such popup. This is done by setting window.returnValue inside popup, but guess what? It does not work! There are a lot of reasons for this feature not to work and a lot of local workarounds, but that all suck, so I killed a lot of time to find An Ultimate Solution to situations when returnValue is undefined. And it is quite simple (: As always!
On caller page create a callback function which will be called from popup to update data:
Then prepare dialogArguments on a caller page and execute showModalDialog:
And now for a modal popup. When you ready to send data back to parent window just call your callback function!
That's it!
P.S. I hope people using this tip do know JavaScript and programming in general.
On caller page create a callback function which will be called from popup to update data:
function modalCallback(newData) {
globalVar = newData;
// globalVar is some external variable you would like to update.
// Actually you may place any code here!
}
Then prepare dialogArguments on a caller page and execute showModalDialog:
var args = {'callback': modalCallback};
window.showModalDialog('popup.html', args);
// Put the code to process recieved data here!
And now for a modal popup. When you ready to send data back to parent window just call your callback function!
window.dialogArguments.callback(dataFromPopup);
That's it!
P.S. I hope people using this tip do know JavaScript and programming in general.








Unregistered user # Friday, July 10, 2009 12:19:58 PM
Unregistered user # Sunday, September 13, 2009 11:59:15 AM
Unregistered user # Thursday, October 15, 2009 9:07:42 AM
Unregistered user # Friday, November 20, 2009 11:01:03 AM
Aux # Saturday, November 21, 2009 12:01:53 PM
Unregistered user # Thursday, September 2, 2010 1:34:09 PM
Unregistered user # Wednesday, August 3, 2011 5:50:10 AM
Unregistered user # Wednesday, August 10, 2011 9:25:17 AM
Unregistered user # Friday, January 27, 2012 1:49:23 PM
Unregistered user # Monday, January 30, 2012 7:04:30 AM
Aux # Tuesday, February 7, 2012 9:58:43 AM