Solved

IE7 and clientHeight

Posted on 2006-06-22
8
1,571 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 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
Industry Leaders: 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!

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

729 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