I'm trying to detect the browser's current size (width and height). I know it's super easy in jQuery with $(document).width and $(document).height
, but I don't want to add the size of the jQuery lib to the project, so I'd rather just use built in JavaScript. What would be the short and efficient way to do the same thing with JavaScript?
According to the Worldwide Screen Resolution Stats (Sept 2021 – Sept 2022), the most common screen resolutions across mobile, desktop, and tablet are: 1920×1080 (9.94%) 1366×768 (6.22%) 360×640 (5.88%)
Use window. innerWidth and window. innerHeight to get the current screen size of a page.
The 'Browser width - bucketed' dimension shows the width of the browser window, classified in groups of 100 pixels. This dimension is useful when you want to understand how wide visitors see your content. Understanding how wide your content is typically viewed can allow you to optimize content for viewing.
Which Is The Standard Webpage Size? The standard webpage size uses a maximum width of 1440 pixels for Desktops. This is because most desktop resolutions use a wider resolution nowadays (1920x1080). However, most websites are fully responsive nowadays, which means they won't use fixed dimensions.
// first get the size from the window // if that didn't work, get it from the body var size = { width: window.innerWidth || document.body.clientWidth, height: window.innerHeight || document.body.clientHeight }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With