Reputation: 1315
I am opening a modal popup window. Then I access a parent window textbox and other attributes using window.opener
. It is working fine in firefox but not in IE8. It gives error 'window.opener is null'. How can I access parent window attributes in child window which works in both browsers.
Upvotes: 20
Views: 74786
Reputation: 3091
As a cross-browser alternative, you can give a custom attribute to the new window while you are opening it:
var popup = window.open(...);
popup.isPopup = true;
Then, in the referred page:
if (window.isPopup) {
// Do something
}
else {
// Not in a popup
}
Upvotes: 1
Reputation: 313
Disable Internet Explorer's "Protected Mode", which prevents access to this object.
The steps for this are:
Now you should be able to access the window.opener object.
Upvotes: 1
Reputation: 3954
The approach I would take is the following:
OpenWindow
, that browser sniffs for the window.opener
methodFor example:
if(window.opener == undefined) {
//probably not Firefox...
}
and if it finds it then uses it, else it tests for the IE variant and uses it. And then it checks Safari's version, etc...
Upvotes: 0
Reputation: 111
There are two ways to solve the problem: Note: "window.opener" is not supported by IE if "showModalDialog" is been used.
1) Instead of "window.showModalDialog" use "window.open"
2) If you want to use "window.showModalDialog" then do the following:
<script language="javascript" type="text/javascript">
function YourFunction()
{
var opener = null;
if (window.dialogArguments) // Internet Explorer supports window.dialogArguments
{
opener = window.dialogArguments;
}
else // Firefox, Safari, Google Chrome and Opera supports window.opener
{
if (window.opener)
{
opener = window.opener;
}
}
// write you code and refer "opener"
window.close();
}
</script>
Upvotes: 10
Reputation: 920
You can pass arguments to showModalDialog function. Simply pass window object as an argument.
window.showModalDialog(theURL, window);
Yo can access the arguments from the modal window using dialogArguments. See: http://msdn.microsoft.com/en-us/library/ms533723%28VS.85%29.aspx
var openerWindow = window.dialogArguments;
Upvotes: 8