现在的位置: 首页 > 综合 > 正文

asp.net中如何获得屏幕分辨率

2011年08月03日 ⁄ 综合 ⁄ 共 480字 ⁄ 字号 评论关闭

今天下载壁纸时发现这样一个比较人性化的设置:

那么这里是如何检测到“电脑的分辨率”的?下面是一个简单的解决方法,但是存在缺陷。 


<script language="javascript">

var width = screen.width;
var height = screen.height;

if( width < 1280 || height < 1024)
{
    alert("This web page is best viewed with a screen resolution of 1280 by 1024 or higher.  Your current resolution is " + width + " by " + height + ".  If possible please change your resolution.");
}
else
{
    alert("Your screen resolution is pretty big!")
}
</script>


上面的程序能够在google chrome下得到正确的屏幕的分辨率,但是在ie下得到的数字相差比较大。

浏览器 宽度 高度 与实际比较

chrome 1366 769  正确

ie9 1249 702 有误差

 

抱歉!评论已关闭.