The JavaScript Window opener property refers to the window or frame that opened the current window. It is commonly used to access and manipulate the parent window from a child window or frame.
Here are some examples of how the opener property can be used in JavaScript code:
- To access the parent window from a child window, you can use the following code:
var parent = window.opener;
// you can now access the parent window's properties and methods
parent.document.getElementById('myElement').innerHTML = 'hello';
- To close the parent window from a child window, you can use the following code:
var parent = window.opener;
// you can now close the parent window
parent.close();
- To access the parent window’s variables from a child window, you can use the following code:
var parent = window.opener;
// you can now access the parent window's variables
var parentVariable = parent.myVariable;
Overall, the opener property provides a convenient way to access and manipulate the parent window from a child window or frame. It can be used to pass data, execute functions, or perform other tasks on the parent window.
Leave a Reply