I want to provide my visitors the ability to see images in high quality, is there any way I can detect the window size?
Or better yet, the viewport size of the browser with JavaScript? See green area here:
It includes, among other things, a responsive design mode from the Tools menu (see screenshot). And from the Web Developer Toolbar, click on Resize tab and select Display Window Size (see screenshot) which shows window and more importantly viewport size.
A viewport is defined by the size of the rectangle filled by a web page on your screen. The viewport is the size of the browser window, minus the scroll bars and toolbars. Browsers use “CSS pixels.” For many devices, such as those with retina screens, the viewport is smaller than the advertised device resolution.
It is not possible to get the height of the screen from CSS. However, using since CSS3 you can use media queries to control the display of the template as per the resolution. If you want to code on the basis of height using media queries, you can define style-sheet and call it like this.
@media (width)
and @media (height)
values const vw = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) const vh = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
window.innerWidth
and window.innerHeight
@media (width)
and @media (height)
which include scrollbarsinitial-scale
and zoom variations may cause mobile values to wrongly scale down to what PPK calls the visual viewport and be smaller than the @media
valuesundefined
in IE8-document.documentElement.clientWidth
and .clientHeight
@media (width)
and @media (height)
when there is no scrollbarjQuery(window).width()
which jQuery calls the browser viewportmatchMedia
to obtain precise dimensions in any unitIf 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