Solved

IE7 and clientHeight

Posted on 2006-06-22
8
1,559 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

777 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