Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visible window height instead of $(window).height();

Is there any way to get the visible height of the whole page from inside an iframe, $(window).height() gives me the iframes height?

like image 336
curly_brackets Avatar asked Aug 10 '11 09:08

curly_brackets


People also ask

How do I make my window visible height?

$(window). height() gives you the height of the view pane. $(window). height() works better as it's cross-browser.

What is $( window height ()?

The . height() method is recommended when an element's height needs to be used in a mathematical calculation. This method is also able to find the height of the window and document. $( document ).

How does jquery calculate window height?

Basically, $(window). height() give you the maximum height inside of the browser window (viewport), and $(document). height() gives you the height of the document inside of the browser. Most of the time, they will be exactly the same, even with scrollbars.

How do you find the height of a viewport?

You can use the window. innerHeight property to get the viewport height, and the window. innerWidth to get its width. let viewportHeight = window.


2 Answers

If you are using frames, you can get the height of the outermost window by using window.top in the jQuery constructor. The height of window.top will get the height of the browser window.

$(window.top).height(); 

Edit: Updated window.top reference as Mozilla moved their documentation around.

like image 121
lonesomeday Avatar answered Sep 17 '22 15:09

lonesomeday


I have always used this implementation

window.innerHeight or document.body.clientHeight or document.documentElement.­clientHeight depending on the browser.

But i don't see why jquery's $(window).height() wont work for your visible height ?

like image 33
MarutiB Avatar answered Sep 21 '22 15:09

MarutiB