Solved

IE7 and clientHeight

Posted on 2006-06-22
8
1,551 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now