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 get domain name information from a Domain using Python
- ModulenotFoundError: no module named 'debug_toolbar' -SOLUTION
- How to create superuser in django project hosted in cPanel without terminal
- CSS & images not loading in django admin | cpanel without terminal
- Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
- How to sell domain name on Godaddy (2023)
- TemplateSyntaxError at / Could not parse the remainder: ' + 1' from 'forloop.counter0 + 1'
- urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0
Related Article