Javascript Browser Window close() Method close a open window

Introduction

Open "www.java2s.com" in a new window, and use close() to close the window:

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="openWin()">Open java2s.com in a new window</button>
<button onclick="closeWin()">Close the new window (java2s.com)</button>

<script>
var myWindow;//from ww w. j av  a2s  .  c  o  m

function openWin() {
  myWindow = window.open("https://www.java2s.com", "_blank", "width=500, height=500");
}

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

</body>
</html>



PreviousNext

Related