IE 6 - clientWidth sometimes 0!?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    IE 6 - clientWidth sometimes 0!?

    Hi,

    I have an iframe that gets its own width from document.body.c lientWidth
    (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.framenam e.frameElement. width -- latter works but only if
    containing page is in same domain as iframe, which isn't always the
    case.

    window.setTimeo ut to delay the script would be a last resort.

    Thanks for any ideas.

    Thomas

  • Dietmar Meier

    #2
    Re: IE 6 - clientWidth sometimes 0!?

    Tom wrote:
    [color=blue]
    > window.setTimeo ut to delay the script would be a last resort.[/color]

    You should use the document's readyState property instead:

    window.onload = function() {
    if (typeof document.readyS tate == "undefined" ) {
    myFunction();
    }
    else {
    if (document.ready State == "complete") {
    myFunction();
    }
    else {
    document.onread ystatechange = function() {
    if (document.ready State == "complete") {
    document.onread ystatechange = null;
    myFunction();
    }
    }
    }
    }
    }
    ....
    function myFunction() {
    // ... do something with document.body.c lientWidth ...
    }

    ciao, dhgm

    Comment

    • Tom

      #3
      Re: IE 6 - clientWidth sometimes 0!?

      Thanks! That fixes the problem completely.

      Comment

      • Tom

        #4
        Re: IE 6 - clientWidth sometimes 0!?

        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.

        Comment

        • Tom

          #5
          Re: IE 6 - clientWidth sometimes 0!?

          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.

          Comment

          • Dietmar Meier

            #6
            Re: IE 6 - clientWidth sometimes 0!?

            Tom wrote:
            [color=blue]
            > I checked the readyState within the myFunction function and even when
            > it is "complete" it often doesn't get a correct value for clientWidth.[/color]

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

            ciao, dhgm

            Comment

            Working...