How to get the window size in JavaScript
๐
June 28, 2021
๐JavaScript
Today weโll show you how to get the window size in JavaScript. In the previous article, we discussed how to get the screen size in JavaScript.
Checkout more articles on JavaScript
- Navigator object in JavaScript
- Methods of Promises in JavaScript
- 7 JavaScript One-Liners that you should know
- Add days to a date in JavaScript
- How to copy text to the clipboard using JavaScript
Get the two different types of the window size
1. Get the window outer size
window.outerWidth
Gets the width of the outside of the browser window.
window.outerHeight
Gets the height of the outside of the browser window.
const windowOuterWidth = window.outerWidth; // Output: 1109
const windowOuterHeight = window.outerHeight; // Output: 620
Window outer size - Clue Mediator
2. Get the window inner size
window.innerWidth
Gets the width of the content area of the browser window including, if rendered, the vertical scrollbar.
window.innerHeight
Gets the height of the content area of the browser window including, if rendered, the horizontal scrollbar.
const windowInnerWidth = window.innerWidth; // Output: 780
const windowInnerHeight = window.innerHeight; // Output: 532
Window inner size - Clue Mediator
I hope you find this article helpful.
Thank you for reading. Happy Coding..!! ๐