JavaScript的screen 对象拥有浏览器屏幕的信息。可用于显示屏幕宽度、高度、颜色深度、像素深度等。
screen 对象是 window 属性,因此可以通过以下方式访问它:
或者,
window.screen
screen
JavaScript Screen 对象的属性
返回浏览器信息的屏幕对象有很多属性。No. | 属性 | 描述 |
---|---|---|
1 | width | 返回屏幕的宽度 |
2 | height | 返回屏幕的高度 |
3 | availWidth | 返回可用宽度 |
4 | availHeight | 返回可用高度 |
5 | colorDepth | 返回颜色深度 |
6 | pixelDepth | 返回像素深度。 |
JavaScript 屏幕对象示例
让我们看看屏幕对象的不同用法。<script>
document.writeln("<br/>screen.width: "+screen.width);
document.writeln("<br/>screen.height: "+screen.height);
document.writeln("<br/>screen.availWidth: "+screen.availWidth);
document.writeln("<br/>screen.availHeight: "+screen.availHeight);
document.writeln("<br/>screen.colorDepth: "+screen.colorDepth);
document.writeln("<br/>screen.pixelDepth: "+screen.pixelDepth);
</script>
screen.width: 1366 screen.height: 768 screen.availWidth: 1366 screen.availHeight: 728 screen.colorDepth: 24 screen.pixelDepth: 24