Connecting Tech Pros Worldwide Help | Site Map

IE7 and document.documentElement.clientHeight

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 29th, 2008, 05:25 PM
vunet
Guest
 
Posts: n/a
Default IE7 and document.documentElement.clientHeight

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!!!

  #2  
Old August 31st, 2008, 08:55 AM
Felix Stahlberg
Guest
 
Posts: n/a
Default Re: IE7 and document.documentElement.clientHeight

Hi,
Quote:
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.