Javascript DOM HTML Document defaultView Property get window size

Introduction

Get the size of the window:

View in separate window

<!DOCTYPE html>
<html>
<body>
<p>Return the window's width and height:</p>

<button onclick="myFunction()">Get window size</button>

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

<script>
function myFunction() {/*from w  w w  .  java 2s .  c om*/
  var x = document.defaultView;
  var w = x.innerWidth;
  var h = x.innerHeight;
  document.getElementById("demo").innerHTML = "Width: " + w + "<br>Height: " + h;
}
</script>

</body>
</html>



PreviousNext

Related