gpt4 book ai didi

javascript - 弹出窗口不保留 Safari 中的宽度/高度尺寸

转载 作者:行者123 更新时间:2023-11-28 05:13:57 25 4
gpt4 key购买 nike

我正在使用此脚本打开一个具有特定大小的弹出窗口并将其居中。它按预期工作,但在 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 支持所有浏览器:

var width = window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;

var heigth = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;

可能是因为这使用了 body.clientHeight/body.clientWidth,但不是 100% 确定。
希望这有帮助!

关于javascript - 弹出窗口不保留 Safari 中的宽度/高度尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com