Close the newly opened window by calling the close() method in JavaScript

Description

The following code shows how to close the newly opened window by calling the close() method.

Example


<!--from ww  w.j  av a  2s . c om-->
<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">

var java2sWin =window.open("http://www.java2s.com/","myWindow");
java2sWin.resizeTo(500, 500);
java2sWin.moveTo(100, 100);

java2sWin.close();
</script>
</body>
</html>

Click to view the demo

The code above generates the following result.

Close the newly opened window by calling the close() method in JavaScript