Solved

Scroll Height in FireFox

Posted on 2010-08-16
4
679 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
Comment Utility
Try use: document.getElementById("apDiv1").style.height = document.body.offsetHeight+ 'px';
0
 
LVL 9

Author Comment

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

Accepted Solution

by:
HagayMandel earned 500 total points
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to count occurrences of each item in an array.

772 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

10 Experts available now in Live!

Get 1:1 Help Now