Created
December 4, 2014 09:50
-
-
Save clarkdave/ee2616885f7763a280a4 to your computer and use it in GitHub Desktop.
Create JS popup centered on screen (dual-screen friendly)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from here: http://www.xtf.dk/2011/08/center-new-popup-window-even-on.html | |
w = 800 | |
h = 600 | |
dualScreenLeft = if window.screenLeft isnt undefined then window.screenLeft else screen.left | |
dualScreenTop = if window.screenTop isnt undefined then window.screenTop else screen.top | |
width = if window.innerWidth then window.innerWidth else ( | |
if document.documentElement.clientWidth then document.documentElement.clientWidth else screen.width) | |
height = if window.innerHeight then window.innerHeight else ( | |
if document.documentElement.clientHeight then document.documentElement.clientHeight else screen.height) | |
left = ((width / 2) - (w / 2)) + dualScreenLeft | |
top = ((height / 2) - (h / 2)) + dualScreenTop | |
opts = "width=#{w},height=#{h},top=#{top},left=#{left}" | |
popup = window.open(url, '', opts) | |
popup.focus() if window.focus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment