473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

strange behaviour with document.body.clientWidth

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>

Jan 17 '07 #1
2 3340
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.clientWi dth:b.clientWidth?b.clientWidth:0;

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

Jan 17 '07 #2
tom
www.publicante.com

Jan 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Torsten Reiners | last post by:
Hi, it might be a simple solution but I do not see it. The problem is that I have the following file stored on my local harddrive. All references are URL to a remote computer. It is working,...
2
by: gregl | last post by:
Anyone know how to obtain the true size of the html document's body? The control contains the size that the control was set to. The body object appears to contain the same size. That information...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
2
by: X t l a n | last post by:
Hello. I've noticed that Mozilla browsers older than 1.1 release don't support document.body.clientWidth but I would like to know dimensions of client workspace area. How to get them?...
7
by: dd | last post by:
Hello all. First, I'm a newbie to javascript but not to ASP. Secondly I've been searching for the answer for two hours and I decided to finally post this question. I'm trying to take a...
6
by: maya | last post by:
<tabletag is being ignored here.. why is this.. <div id="img1"> <script type="text/javascript" language="JavaScript"> var cw = document.body.clientWidth; var ch =...
3
by: Cylix | last post by:
As I know, the document height is depend on browser and OS usering using, is there any way to get the height for that particular document height? Thank you.
5
by: dmk | last post by:
Hi All, function getWindowSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE myWidth = window.innerWidth; myHeight =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.