Created
April 22, 2017 01:29
-
-
Save silviopaganini/8e16c9d4138a7cdc0e870ee6070591bf to your computer and use it in GitHub Desktop.
Open popup
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 default function windowPopup(width, height, url, title, win) { | |
if (typeof width !== 'number' || typeof height !== 'number') { | |
throw new TypeError('Width and height must be numbers'); | |
} | |
if (typeof url !== 'string') { | |
throw new TypeError('Url must be string'); | |
} | |
if ((typeof title !== 'string') && (typeof title !== 'undefined')) { | |
throw new TypeError('Title must be string'); | |
} | |
const winRef = win || window; | |
const left = (winRef.outerWidth / 2) + ((winRef.screenX || winRef.screenLeft || 0) - (width / 2)); | |
const top = (winRef.outerHeight / 2) + ((winRef.screenY || winRef.screenTop || 0) - (height / 2)); | |
return winRef.open(url, title || '', `toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=${ width }, height=${ height }, top=${ top }, left=${ left}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment