IE shows false and Firefox shows true

Discussion in 'Javascript' started by Gianni, Jul 10, 2009.

  1. Gianni

    Gianni Guest

    I get different results with the following script
    in IE and Firefox.

    tes.gif does not exist so it should show false
    on both browsers.

    IE shows false and Firefox shows true.
    Am I misunderstanding something?


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <script type="text/javascript">
    function alertComplete()
    {
    var msg = document.getElementById("testid").complete;
    alert(msg);
    }
    </script>

    </head>

    <body onload="alertComplete()">
    <img id="testid" src="tes.gif" alt="test gif" />
    </body>
    </html>
    Gianni, Jul 10, 2009
    #1
    1. Advertising

  2. Gianni wrote:
    > I get different results with the following script
    > in IE and Firefox.
    >
    > tes.gif does not exist so it should show false
    > on both browsers.
    >
    > IE shows false and Firefox shows true.
    > Am I misunderstanding something?


    Yes. Neither is the `onload' event an indication that all images in the
    document have been loaded, nor is `complete' an interoperable (standard)
    property.

    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head>
    > <title>Test</title>
    > <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>


    XHTML or HTML?

    > <script type="text/javascript">
    > function alertComplete()
    > {
    > var msg = document.getElementById("testid").complete;
    > alert(msg);
    > }
    > </script>
    >
    > </head>
    >
    > <body onload="alertComplete()">
    > <img id="testid" src="tes.gif" alt="test gif" />
    > </body>
    > </html>



    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Jul 10, 2009
    #2
    1. Advertising

  3. Gianni

    Gianni Guest

    Thomas 'PointedEars' Lahn wrote:
    > Gianni wrote:
    >> I get different results with the following script
    >> in IE and Firefox.
    >>
    >> tes.gif does not exist so it should show false
    >> on both browsers.
    >>
    >> IE shows false and Firefox shows true.
    >> Am I misunderstanding something?

    >
    > Yes. Neither is the `onload' event an indication that all images in the
    > document have been loaded, nor is `complete' an interoperable (standard)
    > property.
    >
    >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    >> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    >> <html xmlns="http://www.w3.org/1999/xhtml">
    >> <head>
    >> <title>Test</title>
    >> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    >
    > XHTML or HTML?


    Thanks for responding.

    You seem to imply that this is no way to ensure that
    a document has finished loading? Is there a way of
    doing this?

    You ask XHTML or HTML? I thought what I had specified,
    in the script, was XHTML, but you seem to imply from
    your question that the script is ambiguous? How can
    I change it for the better?
    Gianni, Jul 10, 2009
    #3
  4. Gianni wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> Gianni wrote:
    >>> I get different results with the following script
    >>> in IE and Firefox.
    >>>
    >>> tes.gif does not exist so it should show false
    >>> on both browsers.
    >>>
    >>> IE shows false and Firefox shows true.
    >>> Am I misunderstanding something?

    >> Yes. Neither is the `onload' event an indication that all images in the
    >> document have been loaded, nor is `complete' an interoperable (standard)
    >> property.
    >>
    >>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    >>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    >>> <html xmlns="http://www.w3.org/1999/xhtml">
    >>> <head>
    >>> <title>Test</title>
    >>> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    >> XHTML or HTML?

    >
    > Thanks for responding.
    >
    > You seem to imply that this is no way to ensure that
    > a document has finished loading?


    There is no way to ensure that when the `load' event occurs (sorry for using
    the wrong name before) the document *and* all its referred content (e.g
    images) have been (down)loaded (and displayed).

    > Is there a way of doing this?


    Probably yes, but the approach that is arguably the most reliable is not a
    standards-compliant one (and so certainly none that results in Valid HTML or
    XHTML). Your `img' elements need a proprietary `onload' attribute, and you
    can hope for that in the code called there, if it is called, a counting
    property that is initialized with zero is increased by one each time. You
    can then, after each increase, determine if the current property value
    equals the number of `img' elements in the document. If that were the case,
    you could assume that all images have been loaded.

    The alternative to that is that you do the same but let the code called be
    assigned by dynamically adding an event listener for the `load' event (which
    is however, again, not specified in a public standard to apply to IMG/img
    element nodes) using standards-compliant or proprietary methods. The risk
    involved is that an image completes loading before you can add the listener,
    but that might be mitigated by using said proprietary `complete' property of
    each element object.

    > You ask XHTML or HTML? I thought what I had specified,
    > in the script, was XHTML, but you seem to imply from
    > your question that the script is ambiguous?


    The markup is.

    > How can I change it for the better?


    Declare and use HTML 4.01. What do you need XHTML for here?


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Jul 10, 2009
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Siemel Naran

    Does true ^ true return false?

    Siemel Naran, Jun 17, 2004, in forum: C++
    Replies:
    19
    Views:
    643
    Chris Theis
    Jun 18, 2004
  2. Pierre Quentel

    "0 in [True,False]" returns True

    Pierre Quentel, Dec 12, 2005, in forum: Python
    Replies:
    59
    Views:
    1,004
    Grant Edwards
    Dec 16, 2005
  3. André
    Replies:
    3
    Views:
    1,552
  4. bdb112
    Replies:
    45
    Views:
    1,293
    jazbees
    Apr 29, 2009
  5. Shea Martin

    false or true == true .... WTF?

    Shea Martin, Apr 5, 2007, in forum: Ruby
    Replies:
    4
    Views:
    93
    Bertram Scharpf
    Apr 5, 2007
Loading...

Share This Page