Chrome/Safari: how to open the same window from different tabs or windows

限于喜欢 提交于 2019-12-25 18:13:05

问题


In a web application, I have an optional popup window into which logging content is being loaded. This window is opened via Javascript using window.open().

The users typically have multiple tabs of the application open and my intention is to always reuse the same popup window (if currently open), no matter from which tab they trigger the popup. To do so, I use code similar to this to open the popup:

    <script>
    function myFunction() {
        var myWindow = window.open("popup.html", "my_popup", "width=600,height=400,status,resizable");
    }
    </script>

This works fine in Firefox and IE - only a single popup window is ever opened and all content that I want to log is being loaded into that window.


Chrome and Safari however, use different popup windows depending on the tab from which the popup is launched.

I assumed that the second parameter of window.open() specifies a target name from a global namespace, which seems to be the case for most browsers. But Chrome and Safari behave as if there were tab-specific namespaces for these target names, i.e. "my_popup" referenced from tab 1 refers to a different target than "my_popup" from tab 2. (to make things more complicated, tabs that have been "duplicated" seem to share the same namespace, i.e. they do reuse the same popup window, but tabs created otherwise don't.)

Is there a way to circumvent this behavior of Chrome and Safari and access the same popup window from all tabs that the user may have open?

Or do I have to assume that this is browser-specific behavior for which there seems to be no workaround?


I have tested this with various browsers:

IE 11.0.9600.18204
All tabs with content from the same domain open/reload a single shared popup window (i.e the target namespace seems to be local per domain).
All tabs with content from file:// URLs reuse the same popup window as tabs with content from http:// URLs that point to the local intranet.

Firefox 46.0.1
All tabs with content from the same domain open/reload a single shared popup window (i.e the target namespace seems to be local per domain).
All tabs with content from file:// URLs use their own single shared popup window (i.e. file:// URLs seem to have their own target namespace).

Edge 20.10240.16384.0
The behavior is inconsistent: in most of my tests, Edge behaved like Firefox, but occasionally like Chrome as well.
I don't have a problem in ignoring Edge for the time being.

Chrome 50.0.2661.94
Each tab opens or reloads its own popup window (i.e the target namespace seems to be local per tab)

Safari 9.1
Each tab opens or reloads its own popup window (i.e the target namespace seems to be local per tab)

By the way, in all of these browsers the behavior does not depend on whether or not the popup window was launched due to user interaction: the behavior is identical between cases where the popup is launched via body onload() and cases where it is loaded via button onclick().


[here's additional background information that I assume not to be relevant to the problem, but who knows... ;-)
Actually, our application does not directly open the popup windows, instead we're using log4javascript which opens a logging window (or in case of Chrome: multiple logging windows). I'm willing to extend the log4javascript code to deal with this and send a patch to the maintainer, but in order to do so I need to solve the basic problem described above]

来源:https://stackoverflow.com/questions/37175028/chrome-safari-how-to-open-the-same-window-from-different-tabs-or-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!