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
Solved

IE7 and clientHeight

Posted on 2006-06-22
8
1,564 Views
Last Modified: 2008-01-09
i get an error when trying to use clientHeight in IE7.  error message is invalid argument...

code:

var divsAndSpacings = 5 + 130 + 9 + 20 + 5 + 40 + 0 + 5 + 20;

var insideScreenHeights = parseInt(document.documentElement.clientHeight);

var mainDivHeights = insideScreenHeights - divsAndSpacings;

document.getElementById("softwarebody").style.height = mainDivHeights + 'px';
0
Comment
Question by:ellandrd
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:geordie007
ID: 16958698

hi ellandrd

it obviouslt differs from client to client, but i just opened up a normal browser, and alerted what the height should be, and it gave me a minus number (-198px to be exact), which would cause an "invalid argument" error in IE. try the following and see what you get:

<script>
var divsAndSpacings = 5 + 130 + 9 + 20 + 5 + 40 + 0 + 5 + 20;

var insideScreenHeights = parseInt(document.documentElement.clientHeight);

var mainDivHeights = insideScreenHeights - divsAndSpacings;

var foo = mainDivHeights + 'px';

document.getElementById("softwarebody").style.height = foo;

alert(foo);
</script>

if it's a minus, that's why you're getting an error.
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16958716
but in ie6 it works fine...
0
 
LVL 7

Accepted Solution

by:
geordie007 earned 500 total points
ID: 16958730

ok, got it...

internet explorer has *always* used document.documentElement.­clientHeight/Width and other more standards compliant browsers have used document.body.clientHeight/Width. this has now changed. ie7 has gone to the more standards method.

so, for ie6 you'll need to use document.documentElement.­clientHeight/Width.
for ie7, ff, etc you'll need to use document.body.clientHeight/Width.

cheers
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 16

Author Comment

by:ellandrd
ID: 16958755
so it finding out what browser version you have changed too? to check if user is ie6 or ie7?
0
 
LVL 7

Expert Comment

by:geordie007
ID: 16958824

exactly. something like

if(ie6){
width = document.documentElement.­clientWidth;
}else{
width = document.body.­clientWidth;
}
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16958879
ok thank you!
0
 
LVL 16

Author Comment

by:ellandrd
ID: 16958885
ive only started developing in IE7 since last week and didnt know they changed standards....

but thank you!

Sean
0
 

Expert Comment

by:tomarmga
ID: 20443960
This is bertter than sensing the IE version

return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 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