Tip: Open a popup window

The window.open method is used to open popup windows. It has the following 3 parameters

<script language="javascript"> 
	var w=window.open(URL,'win_name',features);
 </script>

Parameter NameDescription
URLThe url of web page to be opened in the popup
NameName of this window, if you want to refer it in javascript later
FeaturesA comma separated list of features like 'width=300px,height=400px,top=150px,left=100px,resizable=1'

Below is the complete code to open a popup window

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Open Popup Window</title>
<script language="javascript"> 
	function openPopup(){
		var features='width=500px,height=400px,left=300px,top=100px,resizable=0,scrollbars=1';
		var w=window.open(URL,'win_name',features);
		var w=window.open('http://google.com','win1',features);
		if(w==null){
			alert('Sorry! your browser is not configured to show popups');
		}
	}
 </script>
</head>

<body>
	<input type="button" value="Open New Window" onclick="openPopup()" />
</body>
</html>

 

More Javascript tips