Solved

Scroll Height in FireFox

Posted on 2010-08-16
4
680 Views
Last Modified: 2012-05-10
I have the following line of code:

document.getElementById("apDiv1").style.height = document.body.scrollHeight + 'px';

This works in IE, Safari, Chrome but not in FF.  In FF it returns just the visible portion of the page, not the total height, including the scrolling portion.

I see all sorts of people having this issue and some saying that it is related to the content on the page, but I can't seem to figure out what to fix to fix it.  Is there a better way to get the scrollHeight that isn't impacted?

If not, I can post a link up, there is a ton of code so it will not be too straight forward.
0
Comment
Question by:pmessana
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:HagayMandel
ID: 33450006
Try use: document.getElementById("apDiv1").style.height = document.body.offsetHeight+ 'px';
0
 
LVL 9

Author Comment

by:pmessana
ID: 33450344
Nope, that breaks IE and doesn't fix FF.
0
 
LVL 16

Accepted Solution

by:
HagayMandel earned 500 total points
ID: 33450476
Different approach:

function checkHeight(){
if( window.innerHeight && window.scrollMaxY ) {
var pageHeight = window.innerHeight + window.scrollMaxY;
} else if( document.body.scrollHeight > document.body.offsetHeight ) {
var pageHeight = document.body.scrollHeight;
} else {
var pageHeight = document.body.offsetHeight + document.body.offsetTop;
}
document.getElementById("apDiv1").style.height = pageHeight+'px';
}
</script>

0
 
LVL 9

Author Comment

by:pmessana
ID: 33450867
Bingo!  that worked.

Still not sure why the other one didn't work but now that I have that nifty function I am moving on.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now