using window.open with window.name


The browser window.open method provides a way to access open windows by name. For example,

<h3>window A:</h3> window.open('','myWindowName')

This will open a blank window B with window.name == 'myWindowName'. Then,

<h3>window C:</h3> window.open('http://example.com', 'myWindowName')

This will open example.com in window B.

<h2>The problem:</h2>

Rather than creating a new window with name == 'myWindowName', how can I set the name of an already opened window so that it can be accessed by other windows using window.open? Using Chrome the following does not work:

<h3>1. open the following html in the target window</h3> <!DOCTYPE html> <html> <head> <script>window.name='myWindowName'</script> </head> <body> target window </body> </html>

executing window.name in the target window now produces 'myWindowName'

<h3>2. execute the following js from the console of another window</h3> window.open('http://example.com', 'myWindowName')

The code above opens example.com in a new window (also with window.name 'myWindowName') rather than the target window.


for some reason, in chrome, setting the name in the target window will work if no content is loaded into the window, but once content is loaded setting window.name no longer affects the window.open of other windows.


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:

<h3>1. open new window example.com (or any site)</h3> window.name = 'target' window.was_open = true <h3>2. open new window example.com (or any site)</h3> 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.


  • Overriding window.location on Webbrowser Control
  • Declaration of does not work with Ionic's ion-nav-view in IBM MobileFirst
  • How to add regEx in angular filter
  • Why isn't obj.style.left = “200px”; working in this code?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • Tell Git to stop prompting me for conflicts when none really exist?
  • Security issues with PHP's Readfile method
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • onBackPressed() not being executed
  • JSON response opens as a file, but I can't access it with JavaScript
  • Jquery UI tool tip close icon
  • DomPDF {PAGE_NUM} not on first page
  • Display issues when we change from one jquery mobile page to another in firefox
  • Javascript simulate pressing enter in input box
  • Uncaught Error: Could not find module `ember-load-initializers`
  • req.body is undefined - nodejs
  • Accessing IRQ description array within a module and displaying action names
  • Modifying destination and filename of gulp-svg-sprite
  • Shallow update not allowed (git > 1.9)
  • Importing jscolor library in angular 2
  • jquery mobile loadPage not working
  • Delete MySQLi record without showing the id in the URL
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How to get icons for entities from eclipse?
  • A cron job substitute?
  • How to include full .NET prerequisite for Wix Burn installer
  • Proper way to use connect-multiparty with express.js?
  • Load html files in TinyMce
  • Qt: Run a script BEFORE make
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • JaxB to read class hierarchy
  • Programmatically clearing map cache
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal