open-window.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. *Created by PanJiaChen on 16/11/29.
  3. * @param {Sting} url 子窗口需要打开的页面url
  4. * @param {Sting} strWindowName 子窗口名称
  5. * @param {Sting} title 页面标题
  6. */
  7. export default function openWindow(url, strWindowName, title, w, h) {
  8. // Fixes dual-screen position Most browsers Firefox
  9. // const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left
  10. // const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top
  11. // const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width
  12. // const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height
  13. const width = w || screen.availWidth - 40
  14. const height = h || screen.availHeight - 50
  15. const left = (screen.availWidth - width) / 2
  16. const top = (screen.availHeight - height) / 2
  17. console.log(width, height)
  18. const newWindow = window.open(
  19. url,
  20. strWindowName,
  21. // title,
  22. 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' +
  23. width +
  24. ', height=' +
  25. height +
  26. ', top=' +
  27. top +
  28. ', left=' +
  29. left
  30. )
  31. // Puts focus on the newWindow
  32. if (window.focus) {
  33. newWindow.focus()
  34. }
  35. console.log(url)
  36. // 修改窗口标题
  37. newWindow.onload = function() {
  38. newWindow.document.title = title
  39. }
  40. console.log()
  41. }