get the browser's sceen height, when the console is open - javascript

in order to get the browser's screen height,
window.innerHeight in js and
$(window).height() in jquery is used.
i have a modal(popup) which i calculate and refresh it's position(i make it center aligned) when it's inner html is changed.
so first i need to compare the modal's new height to the browser screen's height before positioning.
Problem:
the problem i have is that when the browser's console is open, the code above doesn't give me the browsers screen height, i gives a much less number
browser height is less when console is opened

To find the entire height,
window.outerHeight
or
screen.availHeight
can be used. This will not consider the console size.

Related

Why i am getting window.innerWidth higher than window.outerWidth and screen.width [duplicate]

Open the console in chrome (whilst on SO) and copy in innerWidth + "|"+outerWidth + "|" + screen.width, for me this will return 2133|1920|1920, apparantly the innerWidth is greater than the outerWidth... As if this isn't strange enough I next tried running this code in firefox and it returns 1920|1936|1920. Apparantly my outerWidth is greater than my screen size. (All screens were normally maximized). Strangely enough running the same code on a 'normal' page (not stackoverflow) will return 1920|1920|1920 in chrome, firefox however still insists my outerWidth is greater than my screen.
Have looked around on google, found a couple of articles regarding the functionality on mobile devices, but nothing seems to explain any of the above observation.
One reason innerWidth could be larger than outerWidth is if your browser is zoomed. I got the following results with the browser in fullscreen mode:
zoom inner outer
75% 1706 1280
90% 1422 1280
100% 1280 1280
110% 1164 1280
The only way I could get outerWidth to be larger than screen.width is by changing the window width by dragging.
There is a difference between getting of innerWidth and outerWidth.
Look at official definitions:
Window.innerWidth: is Width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
Window.outerWidth: The outerWidth attribute must return the width of the client window.
As you can see innerWidth has bound to viewport width, while outerWidth has bound to browser window width.
Therefore outerWidth can be less than innerWidth when your page is just zoomed in, or page view is scaled up.
I think you need to state folloving tag in your page:
<meta name="viewport" content="width=device-width, initial-scale=1">
It will make you page to behave as expected (fit to width limits of screen) in small viewports.
And as a possible cause of large innerWidth is the scripts or styles that can change window dimensions.
If we take the MDN definition of window.outerWidth:
Window.outerWidth read-only property returns the width of the outside
of the browser window. It represents the width of the whole browser
window including sidebar (if expanded), window chrome and window
resizing borders/handles.
And for window.innerWidth:
The read-only Window property innerWidth returns the interior width of
the window in pixels. This includes the width of the vertical scroll
bar if one is present.
Concluding:
The outerHeight and outerWidth take into account the browser window size and not the html visible size. Because of that, the values can change from browser to browser and device to device. Moreover, the values can be larger than the device screen itself.
The innerWidth value includes the scroll if present. This means the width value will not be only referring to the visible part but also the amount of scroll left which could be greater than window.outerWidth.

Browser fixed height with javascript or jquery

How can I have my window/ browser actual height? for example alert($(window).height()); it gives me 639 at full screen but when I reduce the browser height it gives less height. I need always 639 though I reduce the browser height. Is it possible with any jQuery or Javascript method?
NB.alert(window.screen.availHeight); gives the height with toolbar which is bigger than 639(my window height) which I don't want actually.
Thanks.

Get browser window width including scrollbar

I tried to get browser window width with $(window).width();. On IE 10, it does return the full browser width, include the scroll bar. However, on Firefox and Chrome, both return the value without the scroll bar.
How can I get the browser width include with the scroll bar together? Because I need the detected width to be exactly same as CSS.
Thanks.
The first answer was close, but upon further inspection it is a bit more complicated. The body.clientWidth is the width excluding the scrollbars. The window.outerWidth is the width including the scrollbars and other window elements like the window border. The window.innerWidth is the actual width of the window, including scrollbars, but not including the window border.
This will get the full Window's width:
window.outerWidth
NOTE: jQuery's outerWidth() doesn’t work on $(window)
window.innerWidth seems to be the correct answer when needed for responsive design
window.innerWidth will give the width of the HTML and the scrollbar. This value is the value used for device width breakpoints when using media queries in CSS. Essentially, window.innerWidth is equal to the calculated CSS unit 100vw. However, window.outerWidth will give you the width of the entire window.
For example, if you had Chrome's Dev Tools open inside of the browser, window.outerWidth would be the width of the webpage + scroll bar + Chrome's Dev Tools inspector. While window.innerWidth would return the width of just the webpage + scroll bar.

document.body.clientHeight is reporting a much smaller height than expected

I have my browser (FF & Chrome) maximized. document.body.clientHeight is reporting 128. This seems too small. The viewable area is at least 960px and I measured it with a screen ruler. I am not using iFrames. Isn't document.body the body tag which is the viewable area? What am I missing?
If you inspect the body element in Firebug, you'll see that it only expands to the height of its contents. This may be more or less than the height of the viewport, depending on the amount and dimensions of content.
Try document.documentElement.clientWidth and document.documentElement.clientHeight.
See jsFiddle.
Another interesting thing is the viewport (vh and vw) units in CSS.
Does your body tag expand to fill the window? If there isn't enough content to force it to be as tall as the browser's height, you're likely to get back a much smaller value than expected. Try hovering over the body tag in Firebug/Chrome Tools and it should highlight the amount of space it's taking up.
Alternatively you could see if offsetHeight returns different results.

Javascript -- Increase window height by one pixel -- Google Chrome

I'm working on a Chromium extension that runs a context script on a constrained window, and want to increase the window height by one pixel (I need the page to reposition, since I'm injecting HTML into it).
I'm attempting to use the following code:
window.resizeTo(window.innerWidth, window.innerHeight + 1);
but this shrinks the window (I suspect because Chromium resizeTo sets window size, but innerWidth and innerHeight gets the size of the TabContents window pane (not including the top bar and border).
How can I either get the proper size or properly resize the window? Thanks for any advice.
You actually want window.outerHeight/window.outerWidth, which includes all of the browser UI.

Categories