Javascript Browser Window open() Method open a window and close it

Introduction

Open a new window. Use 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;// w  ww  .  j  a  va 2 s . com

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>



PreviousNext

Related