Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.opener alternatives

Tags:

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.

like image 285
dmay Avatar asked Feb 03 '11 11:02

dmay


People also ask

What we can use instead of window open?

open would be just as effective as window. open since document is a child node of window.

Why is window opener null?

If this window was not opened by being linked to or created by another, returns null . If the opener is not on the same origin as the current page, functionality of the opener object is limited. For example, variables and functions on the window object are not accessible.

How do I open a pop up window?

The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.

What is window dialogArguments?

The dialogArguments property returns the parameters that were passed into the window. showModalDialog() method. This lets you determine what parameters were specified when the modal dialog was created.


2 Answers

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>
like image 163
Krishn Y Avatar answered Oct 05 '22 23:10

Krishn Y


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;
like image 37
Kaitnieks Avatar answered Oct 06 '22 00:10

Kaitnieks