Get height and width of browser window
Answered
Chukar posted this in #help-forum
ChukarOP
I want to get the height and width of the browser window using window.innerWidth and window.innerHeight.
But in safari mobile browser, it gives the height and width including the search bar and top bar. How to get the height and width without these?
But in safari mobile browser, it gives the height and width including the search bar and top bar. How to get the height and width without these?
Answered by B33fb0n3
While doing this: https://nextjs-forum.com/post/1314504238566608927#message-1314507031532671016
yes,
yes,
window.outerHeight
gets the height in pixels of the whole browser window. So when you substract it you should get the height of the searchbar and with that you know how height the actual page is. If you just need that value for CSS you can use the unit vhd
like 100vhd
9 Replies
@Chukar I want to get the height and width of the browser window using window.innerWidth and window.innerHeight.
But in safari mobile browser, it gives the height and width including the search bar and top bar. How to get the height and width without these?
you should be able to use
window.visualViewport.width
and window.visualViewport.height
. With that you can get only the visual viewportChukarOP
it also give the same height and width as of innerWidth and innerHeight
@Chukar it also give the same height and width as of innerWidth and innerHeight
can you try it via
document.documentElement.clientHeight
and document.documentElement.clientWidth
?ChukarOP
it also give the same height and width as of innerWidth and innerHeight
@Chukar it also give the same height and width as of innerWidth and innerHeight
can you try it like this:
(also the same for the width)
let maxHeight = Math.max(window.innerHeight || 0, window.outerHeight || 0);
let minHeight = Math.min(window.innerHeight || 0, window.outerHeight || 0);
(also the same for the width)
ChukarOP
maxHeight and minHeight are different but width remains the same
While doing this: https://nextjs-forum.com/post/1314504238566608927#message-1314507031532671016
yes,
yes,
window.outerHeight
gets the height in pixels of the whole browser window. So when you substract it you should get the height of the searchbar and with that you know how height the actual page is. If you just need that value for CSS you can use the unit vhd
like 100vhd
Answer
ChukarOP
thanks
happy to help