Javascript Window Open() & Window Close() Method

The Javascript Window.open() method is used to open the web pages into a new window or a new tab. It depends on the browser settings and the values that are assigned to the parameter. 

Syntax:

window.open(URL, name, specs, replace)

Parameters: This method accepts four parameters as mentioned above and described below:

Return Value: This method creates a new window. 


Window.close():  This method is used to close the window which is opened by the window.open() method. 

Syntax:

window.close()

Parameters: This method does not contain any parameters. 

Return Value: This method does not return any value. 

 <!DOCTYPE html>
 <html lang="en">
 <head>
 	<title>JavaScript</title>
 </head>
 <body>
 	<button onclick="openWindow()">Open Window</button>	
 	<button onclick="closeWindow()">Close Window</button>
 	<script>
 		/* JavaScript Open Close Window Method */
 		var myWindow;
 		function openWindow(){
 			//window.open("http://www.yahoobaba.net","yahoobaba");
			//window.open("http://www.yahoobaba.net","_blank");
 			//window.open("http://www.yahoobaba.net","_parent");
 			myWindow = window.open("http://www.yahoobaba.net","","width=500px,height=200px,left=100px,top=200px");
 		}

 		function closeWindow(){
			myWindow = window.close();
 		}
 	</script>
 </body>
 </html>