Skip to content

Instantly share code, notes, and snippets.

@silviopaganini
Created April 22, 2017 01:29
Show Gist options
  • Select an option

  • Save silviopaganini/8e16c9d4138a7cdc0e870ee6070591bf to your computer and use it in GitHub Desktop.

Select an option

Save silviopaganini/8e16c9d4138a7cdc0e870ee6070591bf to your computer and use it in GitHub Desktop.

Revisions

  1. silviopaganini created this gist Apr 22, 2017.
    20 changes: 20 additions & 0 deletions open-popup.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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}`);
    }