Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scroll Height in FireFox

Posted on 2010-08-16
4
Medium Priority
?
688 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 2000 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

This article discusses how to implement server side field validation and display customized error messages to the client.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

670 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