openWindow.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. export default function openWindow(url, title, w, h) {
  2. // Fixes dual-screen position Most browsers Firefox
  3. const dualScreenLeft =
  4. // eslint-disable-next-line no-restricted-globals
  5. window.screenLeft !== undefined ? window.screenLeft : screen.left;
  6. const dualScreenTop =
  7. // eslint-disable-next-line no-restricted-globals
  8. window.screenTop !== undefined ? window.screenTop : screen.top;
  9. const width = window.innerWidth
  10. ? window.innerWidth
  11. : document.documentElement.clientWidth
  12. ? document.documentElement.clientWidth
  13. // eslint-disable-next-line no-restricted-globals
  14. : screen.width;
  15. const height = window.innerHeight
  16. ? window.innerHeight
  17. : document.documentElement.clientHeight
  18. ? document.documentElement.clientHeight
  19. // eslint-disable-next-line no-restricted-globals
  20. : screen.height;
  21. const left = width / 2 - w / 2 + dualScreenLeft;
  22. const top = height / 2 - h / 2 + dualScreenTop;
  23. const newWindow = window.open(
  24. url,
  25. title,
  26. "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=" +
  27. w +
  28. ", height=" +
  29. h +
  30. ", top=" +
  31. top +
  32. ", left=" +
  33. left
  34. );
  35. // Puts focus on the newWindow
  36. if (window.focus) {
  37. newWindow.focus();
  38. }
  39. }