JavaScript Window Screen

Ang object na window.screen ay naglalaman ng impormasyon ng screen ng user.

Window Screen

window.screen Ang object ay pwedeng isulat na walang prefix na window:

Attribute:

  • screen.width
  • screen.height
  • screen.availWidth
  • screen.availHeight
  • screen.colorDepth
  • screen.pixelDepth

Lapad ng Window Screen

screen.width Ang attribute ay ibibigay ang lapad ng screen ng visitor sa pixel.

Example

Ipakita ang lapad ng screen sa pixel:

document.getElementById("demo").innerHTML = "Screen Width: " + screen.width;

The result will be:



Try It Yourself

Taas ng Window Screen

screen.height Ang attribute ay ibibigay ang taas ng screen ng visitor sa pixel.

Example

Ipakita ang taas ng screen sa pixel:

document.getElementById("demo").innerHTML = "Screen Height: " + screen.height;

The result will be:



Try It Yourself

Magagamit na lapad ng Window Screen

screen.availWidth Ang attribute ay ibibigay ang lapad ng screen ng visitor sa pixel, na inaalis ang mga interface na katangian tulad ng toolbar ng window.

Example

Ipakita ang magagamit na lapad ng screen sa pixel:

document.getElementById("demo").innerHTML = "Available Screen Width: " + screen.availWidth;

The result will be:



Try It Yourself

Magagamit na taas ng Window Screen

screen.availHeight Ang attribute ay ibibigay ang taas ng screen ng visitor sa pixel, na inaalis ang mga interface na katangian tulad ng toolbar ng window.

Example

Ipakita ang magagamit na taas ng screen sa pixel:

document.getElementById("demo").innerHTML = "Available Screen Height: " + screen.availHeight;

The result will be:



Try It Yourself

Window Screen na kaayusan ng kulay

screen.colorDepth Ang attribute ay ibibigay ang bilang ng bit na ginagamit sa pagpapakita ng isang kulay.

Lahat ng modernong kompyuter ay gumagamit ng 24 bit o 32 bit na hardware na kaayusan ng kulay:

  • 24 bits = 16,777,216 magkaibang "True Colors"
  • 32 bits = 4,294,967,296 magkaibang "Deep Colors"

Older computers use 14 bits: 65,536 different "High Colors" resolutions.

Very old computers and old-style mobile phones use 8 bits: 256 different "VGA colors".

Example

Display the screen color depth in bits:

document.getElementById("demo").innerHTML = "Screen Color Depth: " + screen.colorDepth;

The result will be:



Try It Yourself

The #rrggbb (rgb) values used in HTML represent "True Colors" (16,777,216 different colors).

Window Screen Pixel Depth

screen.pixelDepth The property returns the pixel depth of the screen.

Example

Display the screen pixel depth in bits:

document.getElementById("demo").innerHTML = "Screen Pixel Depth: " + screen.pixelDepth;

The result will be:



Try It Yourself

For modern computers, color depth and pixel depth are equal.