弹出窗口不保留Safari中的宽度/高度尺寸
问题描述:
我正在使用此脚本打开并居中具有特定大小的弹出窗口。它按预期工作,Mac OS 10.9.5的Safari 9.0.1版除外,其中窗口以全尺寸打开。 它适用于Mac上的所有其他浏览器。弹出窗口不保留Safari中的宽度/高度尺寸
任何想法为什么指定的窗口大小不适用于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>
答
经过大量的调查,似乎这个问题只发生在这个特定的MacBook上。这不是一个普遍的问题,所以我现在要关闭这个topis。
答
尝试使用这些为宽/高为这个JavaScript支持所有浏览器:
var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var heigth = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
这可能是因为这个使用body.clientHeight /体.clientWidth,但不是100%确定。
希望这有助于!
谢谢,但它没有工作,对不起。 – Meek
啊,这是一个无赖,不能真正帮助你进一步因为我没有一个mac和Safari浏览器不真正在Windows上工作 –