JavaScript Window Screen
window.screen 物件包含有關使用者螢幕的資訊。
Window Screen
可以在沒有 window 字首的情況下編寫 window.screen
物件。
屬性
screen.width
screen.height
screen.availWidth
screen.availHeight
screen.colorDepth
screen.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.