Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the available height and available width of a screen in JavaScript?


The window.screen object has provided many features to get the information regarding the browser screen. It has provided screen.availWidth and screen.availHeight to get the available height and available width of the screen. Let's discuss them individually.

Available Width

Example

The screen.availWidth property returns the true width of the visitor's screen that means it subtracts the width of interface features like the Windows Taskbar. The resultant value will be in pixels.

<html>
<body>
<p id="width"></p>
<script>
   document.getElementById("Width").innerHTML =
   "Available screen width is " + screen.availWidth;
</script>
</body>
</html>

Output

Available screen width is 1366


Available Height

Example

The screen.availHeight property returns the true height of the screen that means it subtracts the interface features like the Windows Taskbar. The resultant value will be in pixels.

<html>
<body>
<p id="height"></p>
<script>
   document.getElementById("height").innerHTML =
   "Available screen width is " + screen.availHeight;
</script>
</body>
</html>

Output

Available screen height is 728