?
Solved

IE7 and clientHeight

Posted on 2006-06-22
8
Medium Priority
?
1,579 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
[X]
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
  • 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 2000 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

770 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