JavaScript window.open() method is used to open a popup window. This popup window will place into the center of the screen.
- popupWinHeight: The height of pop up window on the screen.
- popupWinWidth: The width of pop up window on the screen.
Example 1: This example creates the pop up window without placing it into center.
<!DOCTYPE html> <html> <head> <title> Non-centerd popup window on the screen </title> </head> <body> <h1>GeeksforGeeks</h1> <p> Non-centerd popup window on the screen </p> <script> function createPopupWin(pageURL, pageTitle, popupWinWidth, popupWinHeight) { var left = (screen.width ) ; var top = (screen.height ) ; var myWindow = window.open(pageURL, pageTitle, 'resizable=yes, width=' + popupWinWidth + ', height=' + popupWinHeight + ', top=' + top + ', left=' + left); } </script> 'GeeksforGeeks Website', 1200, 650);"> GeeksforGeeks </button> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

Center popup window: To center the popup window we are changing the values of parameters of open() method as follows:
- left = (screen.width – popupWinWidth) / 2
- top = (screen.height – popupWinHeight) / 4
Example 2: This example creates the pop up window and placing it into center.
<!DOCTYPE html> <html> <head> <title> Centerd popup window on the screen </title> </head> <body> <h1>GeeksforGeeks</h1> <p> Centerd popup window on the screen </p> <script> function createPopupWin(pageURL, pageTitle, popupWinWidth, popupWinHeight) { var left = (screen.width - popupWinWidth) / 2; var top = (screen.height - popupWinHeight) / 4; var myWindow = window.open(pageURL, pageTitle, 'resizable=yes, width=' + popupWinWidth + ', height=' + popupWinHeight + ', top=' + top + ', left=' + left); } </script> 'GeeksforGeeks Website', 1200, 650);"> GeeksforGeeks </button> </body> </html> |
Output:
- Before Clicking the button:

- After Clicking the button:

Recommended Posts:
- Differences between HTML <center> Tag and CSS "text-align: center;" Property
- How to Align modal content box to center of any screen?
- What is the difference between “screen” and “only screen” in media queries?
- JavaScript BOM | Window Screen
- How to get the size of screen, current web page and browser window using jQuery?
- What are the types of Popup box available in JavaScript ?
- Semantic-UI | Popup
- How to open popup using Angular and Bootstrap ?
- How to use the Magnific Popup jQuery plugin?
- How to display popup message when logged out user try to vote ?
- How to refresh parent page on closing a popup ?
- How to fit the image into modal popup using Bootstrap?
- Web Window API | Window locationbar property
- Javascript | Window Open() & Window Close Method
- Javascript | Window Blur() and Window Focus() Method
- Web Window API | Window scrollbars property
- Web Window API | DOM Window fullscreen property
- Web Window API | Window personalbar property
- Web Window API | Window statusbar property
- Web Window API | Window toolbar property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


