The window.name
property in JavaScript is a string that represents the name of the current window. This property can be used to identify the window in a web page that contains multiple windows or frames.
Here is an example of how you can use the window.name
property to identify a window:
// Set the name of the current window to "mainWindow"
window.name = "mainWindow";
// Open a new window and set its name to "popupWindow"
var popupWindow = window.open("https://www.example.com", "popupWindow");
In the example above, we set the window.name
property of the current window to “mainWindow” and we opened a new window and set its window.name
property to “popupWindow”. We can then use these window names to reference the specific windows in our web page.
For example, we can use the window.open()
method to open a new window and specify the window.name
of the window we want to open. Here is an example of how you can use the window.name
property to open a window with a specific name:
// Open the "popupWindow" in a new window
var popupWindow = window.open("https://www.example.com", "popupWindow");
We can also use the window.name
property to access a specific window from another window or frame. Here is an example of how you can use the window.name
property to access a window with a specific name:
// Access the "popupWindow" from the current window
var popupWindow = window.open("", "popupWindow");
// Do something with the "popupWindow" object...
It’s important to note that the window.name
property is a part of the Window object, which represents the current browser window. This means that you must use it in the context of a web page that is running in a browser window. You cannot use it in a standalone JavaScript file or in a Node.js environment. Additionally, the window.name
property is not supported by all browsers, so you should check for compatibility before using it in your web page.
Leave a Reply