Skip to content

Instantly share code, notes, and snippets.

@silviopaganini
Created April 22, 2017 01:29
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 silviopaganini/8e16c9d4138a7cdc0e870ee6070591bf to your computer and use it in GitHub Desktop.
Save silviopaganini/8e16c9d4138a7cdc0e870ee6070591bf to your computer and use it in GitHub Desktop.
Open popup
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