Created
April 14, 2016 15:05
-
-
Save leowebguy/8c1442edc0de89cf213b0ec362442e3e to your computer and use it in GitHub Desktop.
open a centered pop-up window, sending arguments url, title, width, height
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
/* | |
usage > centerPop('http://mypage.com/','mypage','575','440');" | |
*/ | |
function centerPop(url, title, w, h) { | |
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left; | |
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top; | |
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width; | |
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height; | |
var left = ((width / 2) - (w / 2)) + dualScreenLeft; | |
var top = ((height / 2) - (h / 2)) + dualScreenTop; | |
var newWindow = window.open(url, title, 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left); | |
if (window.focus) { | |
newWindow.focus(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment