The JavaScript Window parent property refers to the parent window or frame of 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 parent 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.parent;
// 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.parent;
// 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.parent;
// you can now access the parent window's variables
var parentVariable = parent.myVariable;
Overall, the parent 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