Javascript Browser Window opener Property

Introduction

Write some text to the parent window:

Click the button to write some text in the new window and the parent window.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<script>
function myFunction() {//w  w w . j a  va 2 s  .  co m
  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 opener property returns a reference to the window that created the window.

When opening a window with the window.open() method, use this property from the destination window to return details of the parent window.




PreviousNext

Related