Javascript Browser Screen width Property

Introduction

Get the total width of your screen:

var x = "Total Width: " + screen.width;

Click the button to display the total width of your screen, in pixels.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w  w w .jav a  2 s.c om*/
  var x = "Total Width: " + screen.width + "px";
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The width property returns the total width of the user's screen, in pixels.

Use the height property to get the total height of the user's screen.




PreviousNext

Related