JavaScript Window Screen
window.screen 对象包含有关用户屏幕的信息。
Window Screen
可以在没有 window 前缀的情况下编写 window.screen 对象。
属性
screen.widthscreen.heightscreen.availWidthscreen.availHeightscreen.colorDepthscreen.pixelDepth
Window Screen Width
screen.width 属性返回访问者屏幕的宽度(以像素为单位)。
示例
Display the width of the screen in pixels
document.getElementById("demo").innerHTML =
"Screen Width: " + screen.width;
Result will be
Window Screen Height
screen.height 属性返回访问者屏幕的高度(以像素为单位)。
示例
Display the height of the screen in pixels
document.getElementById("demo").innerHTML =
"Screen Height: " + screen.height;
Result will be
Window Screen Available Width
screen.availWidth 属性返回访问者屏幕的宽度(以像素为单位),减去 Windows 任务栏等界面元素。
示例
Display the available width of the screen in pixels
document.getElementById("demo").innerHTML =
"Available Screen Width: " + screen.availWidth;
Result will be
Window Screen Available Height
screen.availHeight 属性返回访问者屏幕的高度(以像素为单位),减去 Windows 任务栏等界面元素。
示例
Display the available height of the screen in pixels
document.getElementById("demo").innerHTML =
"Available Screen Height: " + screen.availHeight;
Result will be
Window Screen Color Depth
screen.colorDepth 属性返回显示一种颜色的位数。
All modern computers use 24 bit or 32 bit hardware for color resolution
- 24 bits = 16,777,216 different "True Colors"
- 32 bits = 4,294,967,296 different "Deep Colors"
Older computers used 16 bits: 65,536 different "High Colors" resolution.
Very old computers, and old cell phones used 8 bits: 256 different "VGA colors".
示例
Display the color depth of the screen in bits
document.getElementById("demo").innerHTML =
"Screen Color Depth: " + screen.colorDepth;
Result will be
The #rrggbb (rgb) values used in HTML represents "True Colors" (16,777,216 different colors)
Window Screen Pixel Depth
screen.pixelDepth 属性返回屏幕的像素深度。
示例
Display the pixel depth of the screen in bits
document.getElementById("demo").innerHTML =
"Screen Pixel Depth: " + screen.pixelDepth;
Result will be
For modern computers, Color Depth and Pixel Depth are equal.