473,385 Members | 1,606 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,385 software developers and data experts.

IE 6 - clientWidth sometimes 0!?

Tom
Hi,

I have an iframe that gets its own width from document.body.clientWidth
(on onLoad).

In Firefox, clientWidth always has an expected value, but in IE 6 it's
sometimes 0! It seems to depend on the loading of the containing page,
because in local tests IE 6 works fine. Also works when refreshing the
iframe after the containing page has loaded.

Is there a better way to get the width of an iframe from _within_ the
iframe? I've tried scrollWidth, offsetWidth and
parent.framename.frameElement.width -- latter works but only if
containing page is in same domain as iframe, which isn't always the
case.

window.setTimeout to delay the script would be a last resort.

Thanks for any ideas.

Thomas

Jul 23 '05 #1
5 5272
Tom wrote:
window.setTimeout to delay the script would be a last resort.


You should use the document's readyState property instead:

window.onload = function() {
if (typeof document.readyState == "undefined") {
myFunction();
}
else {
if (document.readyState == "complete") {
myFunction();
}
else {
document.onreadystatechange = function() {
if (document.readyState == "complete") {
document.onreadystatechange = null;
myFunction();
}
}
}
}
}
....
function myFunction() {
// ... do something with document.body.clientWidth ...
}

ciao, dhgm
Jul 23 '05 #2
Tom
Thanks! That fixes the problem completely.

Jul 23 '05 #3
Tom
Oops... no, it doesn't!

I checked the readyState within the myFunction function and even when
it is "complete" it often doesn't get a correct value for clientWidth.

If I delay the function by 50ms or so it seems to work reliably. I
think it may have something to do with the local caching of the page,
because I have specifically enabled that (and it's a necessity).

Really, really weird.

Jul 23 '05 #4
Tom
Ok might as well just follow up with my final solution (sorry :))

I'm calling a function that loops every 10ms until a non-zero value is
found for clientWidth, because the time before the value becomes
available seems to depend on the containing page's load time. Evidently
IE is loading and parsing the iframed page from cache before it even
knows how big it's going to be. Arg.

Jul 23 '05 #5
Tom wrote:
I checked the readyState within the myFunction function and even when
it is "complete" it often doesn't get a correct value for clientWidth.


Then IMHO that's an IE bug. This kind of properties may change while
readyState is "interactive", but should not be changed any more when
it's "complete".

ciao, dhgm
Jul 23 '05 #6

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

Similar topics

0
by: svend | last post by:
Hey everyone, this is my first messege to this group, so I hope it's fitting. I've been messing with time alot recently, particularly time formatting. During that, I've observed, that when...
3
by: Andrew DeFaria | last post by:
I have the following php code: function Today2SQLDatetime () { $today = date ("Y-m-d H:i:s"); print "date (\"Y-m-d H:i:s\") returned $today<br>"; return $today; return date ("Y-m-d H:i:s"); }...
3
by: BT | last post by:
Hi. I like to know where and how do you set the ClientHeight and ClientWidth properties? I can see Height,Width,Top,Left in the Properties window. Any suggestion would be very helpful. ...
6
by: Stephane Dalpe | last post by:
Hi all, I just want to know why when I'm installing jdk sometimes ask me to reboot and sometimes he don't. As part of our installation, we launch the jdk installation if it's not already...
2
by: Noah Sussman | last post by:
Hello, I am writing a function to reposition an element based on whether one of its edges is outside the visible area of the browser window (the code is below). My client has asked for code...
0
by: jkhoopohann | last post by:
I am using IE6 and encounter that IE crashes when I try to resize the window size until there is no scrollbar. I don't know if it's caused by my code or it's an IE problem. Below are my codes: ...
2
by: wolfing1 | last post by:
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...
5
by: liketofindoutwhy | last post by:
for the code var node = document.getElementById("something") alert(node.offsetWidth) is very similar to node.clientWidth and node.scrollWidth I just wonder why offsetWidth is well...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.