Languages
[Edit]
EN

JavaScript - get browser window size

3 points
Created by:
Zayaan-Rasmussen
543

In this article, we would like to show you how to get browser window size using JavaScript.

Quick solution:

var windowWidth = window.outerWidth;
var windowHeight = window.outerHeight;

Note:

This solution measures the outer size of the window.

 

Offset interpretation:

Window offset width and height interpretation in JavaScript.
Window offset width and height interpretation in JavaScript.

Practical example

In this section, we present a full example of how to get browser window size.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<body>
  <script>

    var windowWidth = window.outerWidth;
    var windowHeight = window.outerHeight;

    console.log('width: ' + windowWidth);
    console.log('height: ' + windowHeight);

  </script>
</body>
</html>

 

See also

  1. JavaScript - get entire document size

  2. JavaScript - get entire document height

  3. JavaScript - get entire document width

References

  1. Window.outerWidth - Web APIs | MDN
  2. Window.outerHeight - Web APIs | MDN
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join