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
- 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
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
Related Article