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:
Post your comments / questions
Recent Article
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
Related Article