Javascript Browser Window close() Method

Introduction

Use open() to open a new window, and close() to close the new window:

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="openWin()">Open "myWindow"</button>
<button onclick="closeWin()">Close "myWindow"</button>

<script>
var myWindow;/*from   w  w w. j  a  va  2s .  c  o m*/

function openWin() {
  myWindow = window.open("", "myWindow", "width=200,height=100");
  myWindow.document.write("<p>This is 'myWindow'</p>");
}

function closeWin() {
  myWindow.close();
}
</script>

</body>
</html>

The close() method closes the current window.

This method is often used together with the open() method.

close();



PreviousNext

Related