简体   繁体   中英

Is window.opener reliable?

Is JavaScript's window.opener property reliably available across browsers, and immune against any security settings and limitations of any sort? Both the opener and the opened window would be on the same domain.

Has anybody run into troubles, bad experiences using it under certain circumstances?

I'm asking because I'm planning to build a tool that relies heavily on it and should support as many platforms as possible.

I've been a developer on two sites now that make extensive use of window.opener, and I don't know of any time when it failed me. These apps were tested on IE[678], Firefox, and Webkit; I've informally used Opera and not noticed a problem there either.

Now, the "opener" relationship is inherently fragile anyway, because there's not much you can do to prevent your users from visiting "cnn.com" in the main browser window that was used to open your separate popup window. Once the original window has loaded new content, the "child" window's "window.opener" reference won't do you any good anyway. Similarly, when the user goes and opens up a new main-browser window and navigates to your site, your "orphan" windows won't really be able to find it.

Of course I cannot offer you a 100% guarantee that everything will be OK :-) My story is true however. Perhaps my reliance on "window.opener" has not been as serious or deep as what you're planning; I can't really say that everything in my applications depended on that working.

值得注意的是,如果文件不是通过 Chrome 中的 HTTP 连接加载的,window.opener 将不起作用(尽管它在 Safari 中运行良好)。

I have used window.opener in my application and found that its nice to work with. The only limitation it has is if pop up blocker is activated by the user then new window is not opened causing issues some times.

Good replacement for this (if pop up blocker is issue ) is to use yui panel also JQuery UI is a good option.

Other than this i have not come across any issues as such and it worked nicely across browsers.

2020 here. No, window.opener is not reliable. It can be blank in IE11 for a variety of reasons:

1) if you navigate to a new location in the child window, window.opener is cleared on page transition

2) if IE11 is configured in protected mode, window.opener is not set https://social.msdn.microsoft.com/Forums/ie/en-US/5d9efaa1-78d5-45dc-a04d-d9fde768379f/ie-11-windowopener-in-popup-dialog

3) if the file isn't loaded through an HTTP connection in Chrome (as noted in a sibling answer)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM