IE7 and document.documentElement.clientHeight

V

vunet

The code below returns the viewport of the browser window but it does
not work in IE7 because of the document.documentElement.clientHeight:

function pageHeight(){
return window.innerHeight != null ? window.innerHeight :
document.documentElement
&& document.documentElement.clientHeight ?
document.documentElement.clientHeight : document.body != null?
document.body.clientHeight : null;
}

I see this problem all over the forums but I cannot find any valid
solution. How do I fix/handle unsupported object in IE7? The solution
which I found was supposed to work but it does not for me:

if (typeof window.innerWidth != 'undefined'){
h = window.innerHeight
}else if (typeof document.documentElement != 'undefined' &&
typeof document.documentElement.clientHeight != 'undefined' &&
document.documentElement.clientHeight != 0){
// IE6 in standards compliant mode (i.e. with a valid doctype as
the first line in the document)
h = document.documentElement.clientHeight
}else{
h = document.getElementsByTagName('body')[0].clientHeight
}


Thanks!!!
 
F

Felix Stahlberg

Hi,
The code below returns the viewport of the browser window but it does
not work in IE7 because of the document.documentElement.clientHeight:

function pageHeight(){
return window.innerHeight != null ? window.innerHeight :
document.documentElement
&& document.documentElement.clientHeight ?
document.documentElement.clientHeight : document.body != null?
document.body.clientHeight : null;
}
The code seems to be okay for me. When do you call this function?
Probably _before_ the DOM-Tree is loaded? imo this could be the problem.
Try out as follows

(...)
<body onload="alert(pageHeight())">
(...)

regards,
Felix Stahlberg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top