4

I have many popup window.open, used to search for an item, that call back a javascript function from the window.opener to select that item (when the user click on it).

That worked forever in all browsers, but it is not into Edge. I found out that window.opener is "undefined" in Edge only. It doesn't matter if I try it locally or on my web server, I got the same problem. And it can't be a security cross-domain thing, my popup are pages from the same web site.

Is there something I missed about Edge? A new requirement the way we use window.open?

For example, if I have an input button that does:

window.open('search.aspx','searching');

and a javascript function into head part like:

function SelectItem(ID)
{
    // insert magic here
    alert('test');
}

The following javascript code from search.aspx doesn't work in Edge:

window.opener.SelectItem(123);

And if I changed it to

alert(window.opener);

I will see it is undefined.

Edit 1: No, it is not a duplicate of Window.opener in Microsoft Edge undefined when running at localhost. I already read this question before asking mine. My problem is happening not only from localhost, but from web server also. It is not a hostname problem.

Edit 2: Easy way to test it, I get the same problem from the w3schools "Try it yourself" example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open3

Update (solution): I had this problem with Edge 38.14393 (Windows 10 version 1607). I just upgrade to Win10 version 1803 (Edge 42.17134) and now it's working fine as expected. Might been a bug in previous Edge version!

Matt Roy
  • 1,455
  • 1
  • 17
  • 27
  • Do these solutions help? https://stackoverflow.com/questions/31196295/window-opener-in-microsoft-edge-undefined-when-running-at-localhost – AtheistP3ace Jul 05 '17 at 16:17
  • 1
    No. I already read this question before asking mine. My problem is happening not only from localhost, but from web server also. It is not a hostname problem. – Matt Roy Jul 05 '17 at 17:16
  • 2
    I've flag that question to remove the "duplicate" tag. I had the same bug. I had prod1.example.com and prod2.example.com (pointing to public IP), window.opener worked, but on some computer, who had access to dev1.example.com (pointing to local IPs), window.opener was broken on prod1.example.com. I suspect Edge to have flagged *.example.com as "local" because if dev1.example.com, so it broke prod1.example.com. – Tom Apr 18 '18 at 08:58
  • 2
    I also voted for reopening. I cannot understand the behavior of people voting to close such questions. – Simon Bergot Jul 13 '18 at 15:09
  • not supported. see: https://caniuse.com/#feat=rel-noopener – Steven Stark Mar 11 '19 at 22:34

1 Answers1

0

Instead of using window.opener to get a reference to the parent window function. You can assign a function to the newly opened widow like so:

function SelectItem(ID)
{
    // insert magic here
    alert('test');
}

var popup = window.open('search.aspx','searching');

if(popup) {
    popup.SelectItem = SelectItem;
}

In your popup you can now call SelectItem.

gforce301
  • 2,944
  • 1
  • 19
  • 24
  • 1
    I thought that you got a good idea, but sadly it doesn't work either. I put an `alert(popup);` before your "if" and in IE11, as expected, I get "[object Window]", but in Edge, I get "null". – Matt Roy Jul 05 '17 at 17:31