Shadowing Posted December 9, 2012 Share Posted December 9, 2012 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 More sharing options...
DarkxPunk Posted December 9, 2012 Share Posted December 9, 2012 if (document.height > document.body.offsetHeight) {alert("Scrollable");} Link to comment Share on other sites More sharing options...
Shadowing Posted December 9, 2012 Author Share Posted December 9, 2012 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 More sharing options...
dsonesuk Posted December 9, 2012 Share Posted December 9, 2012 Have you tried checking against browser window size screen.availHeight, which should relate to the html element size, as when the body exceeds this, the scroll bars will appear. Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 9, 2012 Share Posted December 9, 2012 I just spent re-testing. Works fine... What's your whole code? Link to comment Share on other sites More sharing options...
dsonesuk Posted December 9, 2012 Share Posted December 9, 2012 I just tested it and it only works in chrome and safari, screen.availHeight works in all major browsers, IE will only recognise when using document.documentElement to retrieve height depending on version Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 9, 2012 Share Posted December 9, 2012 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 More sharing options...
dsonesuk Posted December 9, 2012 Share Posted December 9, 2012 i used window.onload=function(){if (document.body.offsetHeight > screen.availHeight) {alert("Scrollable");}else{alert("unScrollable")}} does this not work for ipad? Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 9, 2012 Share Posted December 9, 2012 Nope, but I think I found a solution, still working on the code, will post in a moment. Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 9, 2012 Share Posted December 9, 2012 (edited) 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 December 9, 2012 by DarkxPunk Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 11, 2012 Share Posted December 11, 2012 (edited) So did it work for you? Edited December 11, 2012 by DarkxPunk Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now