deruse
deruse

Reputation: 2881

document.body.scrollHeight yielding two different results in firefox/chrome

I am trying to get access to the height of the entire page (including scrolling). In chrome, document.body.scrollHeight does this. In firefox, this doesn't work... what is the equivalent in firefox?

Upvotes: 8

Views: 16515

Answers (3)

Travis J
Travis J

Reputation: 82277

<script type="text/javascript">
var scnWid,scnHei;
if (self.innerHeight) // all except Explorer
{
scnWid = self.innerWidth;
scnHei = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
scnWid = document.documentElement.clientWidth;
scnHei = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
scnWid = document.body.clientWidth;
scnHei = document.body.clientHeight;
} 

</script>

Upvotes: 1

FURKAN ILGIN
FURKAN ILGIN

Reputation: 2300

You can use jquery to do this without browser problem.

User jQuery $(document).height() and $(document).scrollTop() functions

Upvotes: 1

sonjz
sonjz

Reputation: 5090

definitely start using jquery, accessing $(document).height() will do all the browser checks for you.

http://api.jquery.com/height/

Upvotes: 1

Related Questions