Solved

Scroll Height in FireFox

Posted on 2010-08-16
4
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

739 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