Skip to content Skip to sidebar Skip to footer

Using Window.open With Window.name

The browser window.open method provides a way to access open windows by name. For example, window A: window.open('','myWindowName') This will open a blank window B with window.nam

Solution 1:

As suggested in the comments above, in order to target a window by name using the window.open method, the target window must have the same origin AND have a common opener.

chrome test:

1. open new window example.com (or any site)

window.name = 'target'window.was_open = true

2. open new window example.com (or any site)

w = window.open('', 'target')
w.was_open//undefined

It is unknown why the same test works when the js is executed in a window console without loading content first (like example.com).

A common window cannot be targeted from multiple origins, or windows with different openers. For example, window.open cannot be used by a bookmarklet to postMessage() to a common window.

Post a Comment for "Using Window.open With Window.name"