On IE9, Win 7 window.open() returns null instead of reference of the opened window
Asked Answered
F

4

16

I am trying something like below,

var myWindow = null;
if(!myWindow || myWindow.closed)
{
    myWindow = window.open(url, windowId);
}
else 
{
    myWindow.focus();   
}

All browsers return the window ref for window.open(), but IE 9 returns NULL. Does anybody have more information on why null is returned or possibly a workaround solution for IE9?

Ferree answered 10/8, 2011 at 16:19 Comment(7)
just when we thought we were past the dark days of IE6...Zweig
Are you sure? It seems to return back an object, not null.Graniteware
I think it returns 'null' if the popup is blocked, eg. if it's an auto-popup. But if it's triggered by, say a click, then it works.Vimineous
Is your target window's URL in a different Zone (e.g. Internet->Intranet, or Internet->Trusted, etc)?Mistress
@Rocket: I tried by unchecking the Pop-Blocker in IE settings, But still it return's NULL. And this code is executed upon a user Click.Ferree
@EricLaw: It is LocalMachine->Intranet i.e. i request for the URL in my Intranet froma static HTML file on my machine. Eventually the static HTML will be a parent application i.e Internet->InternetFerree
@EricLaw: window.open returns a reference object if we uncheck the Enable Protected Mode in Internet Options->Security->Security Level for this zone. Can i get more information on this? My use case is mysite.com opens a popup of someothersite.com. mysite.com will use the JS code given above.Ferree
F
28

window.open returns a NULL reference object if Enable Protected Mode is checked under Internet Options->Security->Security Level for this zone and the ZONE is different i.e. in my case local file opening a popup from Intranet.

window.open returns a reference object even if Enable Protected Mode is checked when mysite.com opens someothersite.com in popup window i.e. Internet->Internet

Ferree answered 11/8, 2011 at 12:14 Comment(0)
A
5

Out of curiosity, what's your windowId? Does it have a space in it?

Because, apparently IE9 will fail if there's a space in the window title.

Andromeda answered 10/8, 2011 at 22:53 Comment(2)
That'll fail on invokation, IE7+ often returns null from the call instead of a handle to the child window.Rotter
The window id does not have any space, its "mywindow"Ferree
B
2

Actually in my case, I was getting window.open reference null if I'm opening localhost or intranet site URL. If my popup contains any internet site url then I'm getting window object in reference. I did following to resolve this:

  • Open IE > Tools > Internet Options
  • Go to Security Tab
  • Enable Protected Mode by clicking the checkbox
  • Restart IE

Now, it started giving me window object reference for popup window opened with Intranet Sites.

Also, it could be the URL problem where it is secure or added in trusted sites zone. If you can provide the URL it will help.

Hope this helps.

Birdhouse answered 7/12, 2016 at 9:37 Comment(0)
B
0

We had this problem with our app. We are using external uploads using Dropbox and it was not working.

This is how we fixed it. Summarizing the different reads and solutions. Please let me know if any part is not correct or does not make sense.

Root Cause:

Starting from IE11, Windows has started assigning the security levels to the applications at the time of startup. Low-Security window and High-security window. Also starting IE11, when new popup opens, it is not a sub-window of the main browser window. Instead, it is a whole new IE11 instance with different security level assigned to it. Usually, the external upload mechanism works using the cross window messaging feature of JavaScript. If that does not work, external uploads do not work. As per windows security standards, a low-security window cannot send a message to the high-security window. Taking a step back and looking at our windows machine, they are shipped by our Internal team. By the default, all our domain web applications are added to trusted sites in our windows machines. But external upload links like Dropbox is not added to the trusted sites. So when you open Our App in IE11, windows automatically marks IE11 window as High-security window. Now, when you try to upload a design file through Dropbox because Dropbox is not trusted site, the new popup that gets created is a new IE11 instance with low-security level. Due to this, after the Dropbox window opened, it loses connection with the parent window that is Our App. This is causing the issue with External uploads

Fix:

  1. Either add both yoursite.com and dropbox.com to trusted sites in IE11 through Internet Options > Security > Trusted Sites or remove them both.

  2. Enable Protected Mode in IE11 by marking Enable Protected Mode in IE11 through Internet Options > Security > Enable Protected Mode and then restart the browser.

This means it is not a real issue for our Customers. If it's not working for them, it is either due to the reason, either of the sites is added to the trusted sites list but not both.

Barb answered 7/9, 2018 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.