Created
September 20, 2018 10:13
-
-
Save nicholasxjy/aa697aaff825b91d852e554e275d7915 to your computer and use it in GitHub Desktop.
open a popup window in center
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
export function popupUrlCenterWindow(url, title, w, h) { | |
const dualScreenLeft = | |
window.screenLeft != undefined ? window.screenLeft : window.screenX | |
const dualScreenTop = | |
window.screenTop != undefined ? window.screenTop : window.screenY | |
const width = window.innerWidth | |
? window.innerWidth | |
: document.documentElement.clientWidth | |
? document.documentElement.clientWidth | |
: screen.width | |
const height = window.innerHeight | |
? window.innerHeight | |
: document.documentElement.clientHeight | |
? document.documentElement.clientHeight | |
: screen.height | |
const left = width / 2 - w / 2 + dualScreenLeft | |
const top = height / 2 - h / 2 + dualScreenTop | |
const newWindow = window.open( | |
url, | |
title, | |
'scrollbars=yes, width=' + | |
w + | |
', height=' + | |
h + | |
', top=' + | |
top + | |
', left=' + | |
left | |
) | |
// Puts focus on the newWindow | |
if (window.focus) { | |
newWindow.focus() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment