【发布时间】:2016-12-21 17:05:39
【问题描述】:
我正在使用这个脚本来打开一个特定大小的弹出窗口并将其居中。它按预期工作,但在 Mac OS 10.9.5 上的 Safari 版本 9.0.1 中,窗口以全尺寸打开。 它适用于 Mac 上的所有其他浏览器。
任何想法为什么指定的窗口大小在 Safari 中不起作用?
function PopupCenter(url, title, w, h) {
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no,scrollbars=yes,resizable=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
}
用法:
<a href="#" onclick="PopupCenter('http://www.google.com','Window title','500','600'); return false;">Click</a>
【问题讨论】:
标签: javascript safari popup