473,503 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!!!
Aug 29 '08 #1
1 10241
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
Aug 31 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
10123
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
7
16256
by: dd | last post by:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly I've been searching for the answer for two hours and I decided to finally post this question. I'm trying to take a...
4
11715
by: Captain Dondo | last post by:
Is it possible to get the actual document size? Not the window size, but the actual rendered document size, which in my case is bigger than the window. I am trying to set up a form entry system...
6
3923
by: maya | last post by:
<tabletag is being ignored here.. why is this.. <div id="img1"> <script type="text/javascript" language="JavaScript"> var cw = document.body.clientWidth; var ch =...
3
50392
by: Cylix | last post by:
As I know, the document height is depend on browser and OS usering using, is there any way to get the height for that particular document height? Thank you.
5
7464
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
8
2470
by: Martin Honnen | last post by:
VK wrote: Mozilla has document.height document.width IE has scrollHeight/scrollWidth, depending on compatMode you will need these properties of document.documentElement or document.body --
21
1885
by: Aaron Gray | last post by:
(Please tell me if this is silly or I am barking up the wrong tree) Can someone check this please on pre W3C DOM browsers :- function getDocumentRoot() { for ( e in document.childNodes) if (...
8
4875
by: dhtml | last post by:
Other than Safari 2, what other browsers that support document.clientHeight ? I would guess some KHTML did. I have found the feature, when it is present, to reliably provide the height of the...
0
7204
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.