gpt4 book ai didi

javascript - 使用 JavaScript 获取浏览器窗口宽度/高度的最可靠方法是什么?

转载 作者:行者123 更新时间:2023-11-28 02:49:19 24 4
gpt4 key购买 nike

我目前正在使用以下条件,但它们无法跨浏览器工作或根本无法工作:

if (typeof (window.innerHeight) == 'number') {
//Non-IE:
//Perform operation using window.innerWidth/Height
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
//IE 6+ in 'standards compliant mode'
//Perform operation using document.documentElement.clientWidth/Height
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
//IE 4 compatible
//Perform operation using document.body.clientWidth/Height
}

我相信我遗漏了一两个条件 - 也许还有另一个我没有考虑到的常见表达方式。

我需要添加什么才能完成此任务?

最佳答案

在页面中包含 jQuery 并使用 $(window).width()$(window).height()

关于javascript - 使用 JavaScript 获取浏览器窗口宽度/高度的最可靠方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4126790/

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