Question

Our web site makes use of showModalDialog. Based on what is done within the dialog, we may or may not wish to reload the page that opened the dialog. We do this by having the dialog JavaScript set window.returnValue to true or false, and then the underlying page inspects that in the return value of the call to showModalDialog.

This works fine when the dialog document and underlying page are loaded from the same origin domain. As is typical with the web, when the dialog's domain doesn't match the page's, the return value from showModalDialog is always undefined.

I've entertained passing the flag from the dialog to the underlying window in different ways. Fortunately, we're targeting browsers that all support postMessage, but the dialog JavaScript doesn't appear to be getting a value for window.opener, so I don't think it can get a reference to the window so it can post a message. Implementing an iframe workaround like this is unfeasible with our code base because it would require us to install iframe recipient documents on multiple sites that can all open this same dialog.

Is there a better way for us to have a dialog communicate with cross-origin opening pages without requiring that they reload?

Was it helpful?

Solution

I may have found my own answer. From what I understand, if I set the document.domain property for both the opener document and the dialog document to the same value, I should be able to access this information. Since both are within subdomains of the same root domain name, it should work. If I try this and it works, I will accept this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top