JavaScript มี window.screen object ให้ข้อมูลหน้าจอผู้ใช้ รวมถึง screen.width และ screen.height
ไวยากรณ์
screen.width; screen.height;
ตัวอย่าง ความกว้าง
<html> <body>
<p id="width"></p>
<script>
document.getElementById("width").innerHTML = "Screen width is " + screen.width;
</script> </body> </html>
ผลลัพธ์
1366
ตัวอย่าง ความสูง
<html> <body>
<p id="height"></p>
<script>
document.getElementById("height").innerHTML = "Screen height is " + screen.height;
</script> </body> </html>
ผลลัพธ์
768
ค่าอยู่ในหน่วยพิกเซล (pixels)