open-window.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 newWindow = window.open(url, title, 'height=' + (screen.availHeight - 50) + ',width=' + (screen.availWidth - 10) + ',top=0,left=0,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no')
  16. // const left = ((width / 2) - (w / 2)) + dualScreenLeft
  17. // const top = ((height / 2) - (h / 2)) + dualScreenTop
  18. const left = (screen.availWidth - width) / 2
  19. const top = (screen.availHeight - height) / 2
  20. console.log(width, height)
  21. const newWindow = window.open(
  22. url,
  23. strWindowName,
  24. // title,
  25. 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' +
  26. width +
  27. ', height=' +
  28. height +
  29. ', top=' +
  30. top +
  31. ', left=' +
  32. left
  33. )
  34. // Puts focus on the newWindow
  35. if (window.focus) {
  36. newWindow.focus()
  37. }
  38. console.log(url)
  39. // 修改窗口标题
  40. newWindow.onload = function() {
  41. newWindow.document.title = title
  42. }
  43. console.log()
  44. }