Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between screen.availHeight and window.height()

I am executing the following Javascript on my browser (Firefox).

  1. console.debug("Screen height = "+ screen.availHeight); //outputs 770

  2. console.debug("Window Height ="+ $(window).height()); //outputs 210 (I am using jQuery as well)

What is the difference between the two? Is 770 in pixels and 210 in mm?

Similarly, when I write $(document).height() and $(window).height(), there is a difference. What is the reason?

like image 208
Akshay Avatar asked Jun 15 '10 10:06

Akshay


People also ask

What is difference between screen and window?

The screen object refers to the actual monitor window or desktop size. Note that if you have a multi-mon setup then you will have multiple screen objects. A window object belongs to a single screen , though not very window belongs to the same screen .

What is window screen availHeight?

Definition and Usage. The availHeight property returns the height of the user's screen. The availHeight property returns the height in pixels. The availHeight property returns the height minus interface features like the Windows Taskbar.

What is difference between window and screen in react native?

window : reports width/height without the soft menu bar. screen : reports entire screen's width/height.

What is innerHeight of window?

innerHeight. The read-only innerHeight property of the Window interface returns the interior height of the window in pixels, including the height of the horizontal scroll bar, if present. The value of innerHeight is taken from the height of the window's layout viewport.


2 Answers

window.outerHeight

It's the height of the window on screen, it includes the page and all the visible browser's bars (location, status, bookmarks, window title, borders, …).

This not the same as jQuery's $(window).outerHeight().

window.innerHeight or $(window).height()

It's the height of the viewport that shows the website, just the content, no browser's bars.

document.body.clientHeight or $(document).height()

It's the height of your document shown in the viewport. If it is higher than $(window).height() you get the scrollbars to scroll the document.

screen.availHeight

It's the height the browser's window can have if it is maximized, including the browser's bars. So when the window is maximized, screen.availHeight === window.outerHeight

screen.height

It simply matches the screen's resolution. So on a 1920×1080 screen, screen.height will be 1080.

screen.availHeight is equal to [screen.height + the operating system's bars], like the taskbar on Windows, the dock and menu on OS X, or whatever is fixed on top or bottom of your screen if you're using Linux.

like image 109
jigfox Avatar answered Sep 17 '22 17:09

jigfox


Wanted to correct a thing stated in @jigfox 's answer:

https://www.w3schools.com/jsref/prop_screen_availheight.asp#:~:text=The%20availHeight%20property%20returns%20the,)%2C%20use%20the%20availWidth%20property.

The availHeight property returns the height of the user's screen, in pixels, minus interface features like the Windows Taskbar.

Tip: To get the height of the screen (excluding the Windows Taskbar), use the availHeight property.

like image 32
RainCast Avatar answered Sep 21 '22 17:09

RainCast