openWindow.js 1.1KB

123456789101112131415161718192021222324252627
  1. /**
  2. *Created by jiachenpan on 16/11/29.
  3. * @param {Sting} url
  4. * @param {Sting} title
  5. * @param {Number} w
  6. * @param {Number} h
  7. */
  8. export default function openWindow(url, title, w, h) {
  9. // Fixes dual-screen position Most browsers Firefox
  10. const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left
  11. const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top
  12. const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width
  13. const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
  14. const left = ((width / 2) - (w / 2)) + dualScreenLeft
  15. const top = ((height / 2) - (h / 2)) + dualScreenTop
  16. const newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left)
  17. // Puts focus on the newWindow
  18. if (window.focus) {
  19. newWindow.focus()
  20. }
  21. }