The opener
property returns a reference to the window that created the window.
opener |
Yes | Yes | Yes | Yes | Yes |
var v = window.opener
A reference to the window that created the window.
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: