Last active
August 30, 2017 10:19
-
-
Save himalay/5dd37180bc67adf8d0cfec871642f883 to your computer and use it in GitHub Desktop.
Open centered popup window
This file contains hidden or 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
// open with html string | |
function openPopupWin (content, width, height) { | |
var w = innerWidth || document.documentElement.clientWidth || screen.width | |
var h = innerHeight || document.documentElement.clientHeight || screen.height | |
var position = 'scrollbars=yes,width=' + width + ',height=' + height | |
position += ',top=' + ((h - height) / 2 + screenTop || screen.top || 0) | |
position += ',left=' + ((w - width) / 2 + screenLeft || screen.left || 0) | |
var popupWin = window.open('about:blank', '', position) | |
popupWin.document.write(content) | |
if (window.focus) popupWin.focus() | |
} | |
// open url with a title | |
function openPopupWin (url, title, width, height) { | |
var w = innerWidth || document.documentElement.clientWidth || screen.width | |
var h = innerHeight || document.documentElement.clientHeight || screen.height | |
var position = 'scrollbars=yes,width=' + width + ',height=' + height | |
position += ',top=' + ((h - height) / 2 + screenTop || screen.top || 0) | |
position += ',left=' + ((w - width) / 2 + screenLeft || screen.left || 0) | |
var popupWin = open(url, title, position) | |
if (focus) popupWin.focus() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment