strange behaviour with document.body.clientWidth

W

wolfing1

I have the following page that is supposed to self-resize to the
image's dimensions when opened, but for some reason it works fine with
Firefox, but in IE6 it doesn't. I added the alert and it gives me a
wildly different value in both browsers. In Firefox, it tells me the
correct browser dimensions, but in IE it says the wrong dimensions,
i.e., the dimensions of the image and not the browser, so when I do the
substraction later it basically resizes by 0,0 (well, 0, -4 but same
thing).
Can anybody see anything wrong about it?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html40/loose.dtd">
<html>
<head>
<title>Size Chart</title>
<link rel="stylesheet" type="text/css" href="/style.css">
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<script language="javascript" type="text/javascript">
var NS = (navigator.appName=="Netscape")?true:false;

function FitPic() {
iWidth = (NS)?window.innerWidth:document.body.clientWidth;
iHeight = (NS)?window.innerHeight:document.body.clientHeight;
alert(iWidth + "." + iHeight);
iWidth = document.images[0].width - iWidth;
iHeight = document.images[0].height - iHeight;
window.resizeBy(iWidth, iHeight);
self.focus();
};
</script>
</head>
<body onload="FitPic();">
<img src="/img/0.jpg" alt="x">
</body>
</html>
 
D

dd

Here's the code I use (same applies to Height):

var d=document,e=d.documentElement,b=d.body,w=window;
return
w.innerWidth?w.innerWidth:e.clientWidth?e.clientWidth:b.clientWidth?b.clientWidth:0;

Hope that works for you. If anyone's got anything better,
I'd be willing to use that :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top