Jump to content

How to get scrollHeight value from document


Shadowing
 Share

Recommended Posts

Hey guy's i'm having problems getting the scrollHeight from the document. The html tags my main objective though is just to detect rather or not the document scroll bar is active or not. So i dont know maybe someone has another idea cause I dont actually need any numbers returned.

Link to comment
Share on other sites

Thanks for the responce DarkxPunk. I tried that couldnt get it to turn truetested while scroll bar was active

	    if (document.height > document.body.offsetHeight) {	   	     return true;	   	    }else{	     	     return false;	    }

What i was trying to do in the first place was trying to see if the body was overflowing but couldnt get that work eitherby setting body to overflow:hidden; Then finding a way to tell if its clipping or not

Link to comment
Share on other sites

Is there any other ideas? Cause that method poses a problem for the iOS devices. Since I am testing this on the iPad, the screen.availHeight does not ignore the browser elements. It simply shows the full screen size.

Link to comment
Share on other sites

This is a perfect, yet long cross platform solution:

var d = document;function getDocumentHeight(){var mx = Math.maxreturn mx(mx(d.body.scrollHeight, d.documentElement.scrollHeight),mx(d.body.offsetHeight, d.documentElement.offsetHeight),mx(d.body.clientHeight, d.documentElement.clientHeight));} function getWindowHeight(){if (window.innerHeight){var mn = Math.min;return mn(d.body.clientHeight, d.documentElement.clientHeight, window.innerHeight)}else if (d.body.clientHeight || d.documentElement.clientHeight){var mn = Math.min;return mn(d.body.clientHeight, d.documentElement.clientHeight)}}if (getDocumentHeight() > getWindowHeight()){alert("Scrollable");}else{alert("Not Scrollable");}

(Actually I guess I am a lier, does not work in IE 7... Working on a quick fix will update code in a second)(Updated and Fixed)

Edited by DarkxPunk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...