Javascript Reference - Window opener Property








The opener property returns a reference to the window that created the window.

Browser Support

opener Yes Yes Yes Yes Yes

Syntax

var v = window.opener

Return Value

A reference to the window that created the window.

Example

The following code shows how to write some text to the source (parent) window.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--   w w w  . j a  v  a  2s . co m-->
<script>
function myFunction() {
    var myWindow = window.open("", "myWindow", "width=200, height=100");
    myWindow.document.write("<p>This is 'myWindow'</p>");
    myWindow.opener.document.write("<p>This is the source window!</p>");
}
</script>

</body>
</html>

The code above is rendered as follows: