gpt4 book ai didi

javascript - 检测真实屏幕分辨率(忽略浏览器缩放等)

转载 作者:搜寻专家 更新时间:2023-11-01 04:42:59 37 4
gpt4 key购买 nike

我需要使用 JavaScript(至少在客户端)获得真实的屏幕分辨率,但 IE 和 Firefox 都有问题,因为当您使用浏览器的内置缩放时它们往往会更改此分辨率。

如何以跨浏览器友好的方式做到这一点?

最佳答案

function getDimension() {
var width = 0, height = 0;
if( typeof( window.innerWidth ) == 'number' ) {
height = window.innerHeight;
width = window.innerWidth;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
height = document.documentElement.clientHeight;
width = document.documentElement.clientWidth;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
height = document.body.clientHeight;
width = document.body.clientWidth;
}
window.alert( 'Width = ' + width + 'Height = ' + height);
}

或(jquery)

height    = $(window).height();
width = $(window).width();

关于javascript - 检测真实屏幕分辨率(忽略浏览器缩放等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5342805/

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