4

When I am trying to access an element of my Parent window from a Pop-up window, I am getting window.opener as undefined.

var opener = window.opener;
if(opener) 
{
    console.log("opener element found");
    var elem = opener.$('.my-parent-element');
    if (elem) {
        console.log("parent element found");
        elem.show(); 
    }
}

Here opener is undefined. Am I doing something wrong?

I have tried parent.window.opener / window.top / window.top.document.bodyetc., but it doesn't help either. It works fine in other browsers.

I have see the question Window Opener Alternative, but I cannot change opening my popup with showModalDialog right away. Probably, this would be last option.

4
  • Is the opener the same host? Has it been redirecting?
    – Timmetje
    May 9, 2014 at 10:17
  • Then I think it has to do with IE security zones: stackoverflow.com/questions/15822885/…
    – Timmetje
    May 9, 2014 at 10:21
  • That sounds a problem of my kind. But does not seem to have a solution? Is it?
    – Shubh
    May 9, 2014 at 10:22
  • Like many IE problems unfortunately yes.
    – Timmetje
    May 9, 2014 at 10:23

2 Answers 2

20

I had the same problem and it was due to Internet Explorer Security Options, in particular because my popup was going to an External website (Internet area) and the parent was an internal page (Intranet area). The "Protected Mode" was only activated for the "Internet". I activated it for the "Local intranet" and now it works.

To find this option in IE:

  • Go to Internet Options
  • Security tab
  • Click on "Internet" or "Local intranet" icon
  • Check or uncheck the option "Enable Protected Mode"
  • Restart IE
5

You can use the showModalDialog function and pass arguments to it, if the browser used is IE. Simply pass window object as an argument.

After that you can access the arguments from the modal window using dialogArguments.

More details can be found in the documentation here: http://msdn.microsoft.com/en-us/library/ms533723%28VS.85%29.aspx

Example of retrieve:

window.showModalDialog(theURL, window);

//in the modal dialog you can use this to retrieve the window.
var openerWindow = window.dialogArguments;
1
  • Sorry for being late. As I said before implementing with showModalDialog would be the last option(so it took some time). I changed my code and ran. All fine. Thanks.
    – Shubh
    May 26, 2014 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.