天天看点

javascript js 使window.open 新窗口居中显示

原文地址:传送门?

openwindow = function (data) {
	var url = data.url;                                          //转向网页的地址;  
	var name = data.title || '选择要添加的页面';                  //网页名称,可为空;  
	var iWidth = data.width || '860';                           //弹出窗口的宽度;  
	var iHeight = data.height || window.innerHeight * 0.8;      //弹出窗口的高度;
	var iTop = (window.screen.height - 30 - iHeight) / 2;       //获得窗口的垂直位置;  
	var iLeft = (window.screen.width - 10 - iWidth) / 2;        //获得窗口的水平位置;  
	window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}

// 调用
openwindow({url: 'https://unnue.com'});
           

原文地址:传送门?

继续阅读