In this article, I will show you to open a popup window using JavaScript. You can customize the new window open features such as directories, width, height, location, resizable etc.
If you set the resizable option to turn off, you’re not able to maximize the window. When the user presses the button, JavaScript event is triggered and it will call the OpenWindow() function. The new window should be opened at the center of the screen.
Example:
<script type="text/javascript">
function OpenWindow() {
winObj = window.open("http://www.google.com", "google",
"width=900,height=500,resizable=no");
winObj.moveTo(250, 250); // Move window to middle
winObj.focus();
parent.window.moveTo(215, 0); // Move the parent window
parent.window.resizeTo(400, 400); // Resize browser window
}
function closeWindow() {
winObj.close();
}
</script>
<form>
<h2>open a popup window </h2>
<br />
click the button
<input type="button" value="Open browser window" onclick="OpenWindow();" />
<p>When you are ready to close the window, click here</p>
<a href="#" onclick="closeWindow();">close the window</a>
</form>
Output: