In this section, we will learn what the window opener property is and how to use it in JavaScript.
JavaScript Window opener Property
When we call the `open()` method, it returns to an object that is basically the `window` object of the opened browser window.
This object has a property named `opener` that points to the `window` object in which the call to the `open()` method occurred.
Window opener Property Syntax:
window.opener
Example: using JavaScript Window opener Property
const wing = window.open("","myWindow","width=400,height=400"); console.log(wing.opener == window);
Output:
true
Browsers usually run each tab (or new window) on a separate process. But when one browser window calls to open another one, some of the browsers usually run both windows in the same process to be able to communicate with each other.
But if we want each browser window to run in a separate process, we can set the value of the `opener` property to `null` and this way, the connection will lose and each window can run in a separate process.
Example: running each window on a separate process
const wing = window.open("","myWindow","width=400,height=400"); wing.opener = null; console.log(wing.opener == window);
Output:
false