Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/13/2023 in all areas

  1. Been a long time since I used a positioned popup window. Had to check the docs for the right options. You can center the popup on the screen by setting the top / left options. These control the top-left corner of the window, so to get it truly center you have to calculate the right offset. There's a standard formula for this. centerPoint = (sizeOfContainer - sizeOfThing) / 2 For this case, your sizeOfContainer is the screen width/height and the sizeOfThing are your popup window's width/height. Run that formula for each to get your top/left values and set them in the window options. const popupWidth = 400, popupHeight = 800; let top = (window.screen.height - popupHeight)/2; let left = (window.screen.width - popupWidth)/2; const win = window.open('', 'formpopup', 'width='+popupWidth+',height='+popupHeight+',resizable,scrollbars,top='+top+',left='+left); The final result may be slightly off (mostly in the height axis) due to the window UI elements since they are not part the calculation. The width/height you specify is for the content area of the window, the UI elements are added on top of that. If the slight offset bugs you, you can fix it after opening the window by re-calculating the offset using the window's outerWidth and outerHeight values for sizeOfThing, then using it's moveTo function to re-position it. top = (window.screen.height - win.outerHeight)/2; left = (window.screen.width - win.outerWidth)/2; win.moveTo(left, top); That may create a noticeable jump after the window opens though.
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.