When you create a new browser window, you pass it a name like this:
myWindow = window.open('http://www.google.com', "googleWindow");
Later you can access the window from the variable you saved it as:
myWindow.close();
Is it possible to access and manipulate a window by it’s name (googleWindow) instead of the variable?
If it is not possible, what is the point giving windows names?
No. Without a reference to the window, you can’t find it again, by name or otherwise. There is no collection of windows.
UPDATE: Here’s how you could do it yourself:
Now,
openWindowwill always open the window, and if the window already exists, it will load the given URL in that window and return a reference to that window. Now you can also implementfindWindow:Which will return the window if it exists, or
undefined.You should also have
closeWindow, so you don’t keep references to windows that you opened yourself:The name is used internally by the browser to manage windows. If you call
window.openwith the same name, it won’t open a new window but instead load the URL into the previously opened window. There are a few more things, from MDN window.open():