/** *Created by PanJiaChen on 16/11/29. * @param {Sting} url 子窗口需要打开的页面url * @param {Sting} strWindowName 子窗口名称 * @param {Sting} title 页面标题 */ export default function openWindow(url, strWindowName, title, w, h) { // Fixes dual-screen position Most browsers Firefox // const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left // const dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top // const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width // const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height const width = w || screen.availWidth - 40 const height = h || screen.availHeight - 50 // 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') // const left = ((width / 2) - (w / 2)) + dualScreenLeft // const top = ((height / 2) - (h / 2)) + dualScreenTop const left = (screen.availWidth - width) / 2 const top = (screen.availHeight - height) / 2 console.log(width, height) const newWindow = window.open( url, strWindowName, // title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left ) // Puts focus on the newWindow if (window.focus) { newWindow.focus() } console.log(url) // 修改窗口标题 newWindow.onload = function() { newWindow.document.title = title } console.log() }