Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS "Window" width-height vs "screen" width-height?

I am wondering a little when I look at this code:

// Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

...

// Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

What is the difference between $(document).height(); and $(window).height();?

like image 497
Jeff Avatar asked Jun 06 '11 17:06

Jeff


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 .

How do you get the height and the width of a page with Javascript?

Use window. innerWidth and window. innerHeight to get the current screen size of a page.

What is the meaning of $( window width ()?

$(window). width() gets the entire width of the window, including things like the scroll bar .


1 Answers

Window is the top level client side object, which contains the document. This jsFiddle shows that both $(window).height() and $(document).height() return the same value: http://jsfiddle.net/jackrugile/5xSuv/

Window is the size of the viewport and does not include any of the chrome or browser interface, if I am not mistaken. I believe that the values of both will always be the same, unless you are referencing something like an iframe within a window.

like image 106
jackrugile Avatar answered Sep 18 '22 14:09

jackrugile