Skip to content

Instantly share code, notes, and snippets.

@clarkdave
Created December 4, 2014 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkdave/ee2616885f7763a280a4 to your computer and use it in GitHub Desktop.
Save clarkdave/ee2616885f7763a280a4 to your computer and use it in GitHub Desktop.
Create JS popup centered on screen (dual-screen friendly)
# 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