Internet Explorer XHTML window.onload issue

Discussion in 'Javascript' started by AndreHaupt, Dec 18, 2007.

  1. AndreHaupt

    AndreHaupt Guest

    Hi,

    Maybe I'm just being thick, but when my Javascript is inside the xhtml
    itself it works fine:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Construction Economics Associates</title>
    <link rel="stylesheet" type="text/css" href="/cea/css/default.css"/
    >

    <script type="text/javascript"> window.onload = function()
    { alert("hello"); }</script>
    </head>

    .....
    </html>

    But when I move it to an external js file, it is not executed in IE:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
    www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Construction Economics Associates</title>
    <link rel="stylesheet" type="text/css" href="/cea/css/default.css"/
    >

    <script src="/javascript/common.js" type="text/javascript"></
    script>
    </head>
    ....
    </html>

    common.js:
    window.onload = function() { alert("hello"); }

    It works in Mozilla though....

    Any ideas?
     
    AndreHaupt, Dec 18, 2007
    #1
    1. Advertising

  2. AndreHaupt

    AndreHaupt Guest

    Oh that's IE7
     
    AndreHaupt, Dec 18, 2007
    #2
    1. Advertising

  3. AndreHaupt

    VK Guest

    On Dec 18, 9:19 pm, AndreHaupt <> wrote:
    > Oh that's IE7


    AFAICT it should not work on any IE because <link> element is not
    properly closed:

    <link rel="stylesheet" type="text/css" href="/cea/css/default.css"/

    instead of

    <link rel="stylesheet" type="text/css" href="/cea/css/default.css" />

    unless it is a copy-n'-past error.

    Besides that ensure that you are serving the page as "text/html" and
    not as "application/html+xml"
    IE doesn't support XHTML, so the only option is to serve it as "text/
    html" so it will be parsed as a broken yet usable HTML by IE.

    All fixes in place and src attribute pointing to the right location, a
    page served as "text/html"

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Construction Economics Associates</title>
    <link rel="stylesheet" type="text/css"
    ref="/cea/css/default.css" />
    <script src="/javascript/common.js" type="text/javascript">
    </script>
    </head>
    <body>
    </body>
    </html>

    will run just fine.
     
    VK, Dec 18, 2007
    #3
  4. AndreHaupt wrote:
    > Oh that's IE7


    Microsoft Internet Explorer does not support XHTML natively to date, nor is
    XHTML required here. Serve HTML 4.01 as text/html and many problems will go
    away.

    You should also use the standardized intrinsic event handler `onload'
    attribute of the `body' element instead of the proprietary event handler
    property `onload' of the host object referred to by the host-defined
    `window' property of the Global Object (or another object in the scope chain).

    BTW, ignore VK.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Dec 18, 2007
    #4
  5. AndreHaupt

    VK Guest

    On Dec 18, 11:13 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > You should also use the standardized intrinsic event handler `onload'
    > attribute of the `body' element instead of the proprietary event handler
    > property `onload'


    A very bad advise from the point of view of content-layout-scripting
    separation: to hardcode some function call into HTML/XHTML tags. What
    exactly standardization body does suggest such approach?
     
    VK, Dec 18, 2007
    #5
  6. VK wrote:
    > On Dec 18, 11:13 pm, Thomas 'PointedEars' Lahn <>
    > wrote:
    >> You should also use the standardized intrinsic event handler `onload'
    >> attribute of the `body' element instead of the proprietary event handler
    >> property `onload'

    >
    > A very bad advise from the point of view of content-layout-scripting
    > separation:


    Nonsense. Whether either the `script' element contains an assignment of a
    reference to a Function object to `window.onload' (or performing an
    equivalent), or the `script' element to contain a function declaration and
    the `onload' property of the `body' element to contain a call to that
    function makes no real difference. The script is always tied to and
    tailored to the markup.

    The real difference here is that the `onload' property is proprietary, and
    both it and a standards-compliant equivalent would require feature-testing
    for themselves, while the `onload' attribute is standardized as per HTML
    4.01 (and supported long before that) and requires no feature-testing on itself.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 18, 2007
    #6
  7. AndreHaupt

    VK Guest

    > >> You should also use the standardized intrinsic event handler `onload'
    > >> attribute of the `body' element instead of the proprietary event handler
    > >> property `onload'


    > > A very bad advise from the point of view of content-layout-scripting
    > > separation:


    > Nonsense. Whether either the `script' element contains an assignment of a
    > reference to a Function object to `window.onload' (or performing an
    > equivalent), or the `script' element to contain a function declaration and
    > the `onload' property of the `body' element to contain a call to that
    > function makes no real difference. The script is always tied to and
    > tailored to the markup.


    Nonsense. :)

    <body onload="someFunction()"> for each and any script on the page
    will try to launch someFunction and it better be in the script and
    really being the one needed onload. This way you create a hardcoded
    link between your HTML structure and your script structure. In some
    organizations it can be a conversion about the onload function name,
    say Java-inspired init() as in my company but there is not such
    convention on any wide run.

    > The real difference here is that the `onload' property is proprietary, and
    > both it and a standards-compliant equivalent would require feature-testing
    > for themselves


    Double nonsense unless NN4 or lower is a requirement. However I liked
    NN I said goodbye to it long ago, so all other descent people did.
     
    VK, Dec 18, 2007
    #7
  8. AndreHaupt

    AndreHaupt Guest

    On Dec 18, 9:08 pm, VK <> wrote:
    > On Dec 18, 9:19 pm, AndreHaupt <> wrote:
    >
    > > Oh that's IE7

    >
    > AFAICT it should not work on any IE because <link> element is not
    > properly closed:
    >
    > <link rel="stylesheet" type="text/css" href="/cea/css/default.css"/
    >
    > instead of
    >
    > <link rel="stylesheet" type="text/css" href="/cea/css/default.css" />
    >
    > unless it is a copy-n'-past error.
    >
    > Besides that ensure that you are serving the page as "text/html" and
    > not as "application/html+xml"
    > IE doesn't support XHTML, so the only option is to serve it as "text/
    > html" so it will be parsed as a broken yet usable HTML by IE.
    >
    > All fixes in place and src attribute pointing to the right location, a
    > page served as "text/html"
    >
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="http://www.w3.org/1999/xhtml">
    > <head>
    > <title>Construction Economics Associates</title>
    > <link rel="stylesheet" type="text/css"
    > ref="/cea/css/default.css" />
    > <script src="/javascript/common.js" type="text/javascript">
    > </script>
    > </head>
    > <body>
    > </body>
    > </html>
    >
    > will run just fine.


    Just a copy-and-paste error yes.

    I'll try your suggestions thanks.
     
    AndreHaupt, Dec 19, 2007
    #8
  9. AndreHaupt

    AndreHaupt Guest

    On Dec 18, 11:26 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > VK wrote:
    > > On Dec 18, 11:13 pm, Thomas 'PointedEars' Lahn <>
    > > wrote:
    > >> You should also use the standardized intrinsic event handler `onload'
    > >> attribute of the `body' element instead of the proprietary event handler
    > >> property `onload'

    >
    > > A very bad advise from the point of view of content-layout-scripting
    > > separation:

    >
    > Nonsense. Whether either the `script' element contains an assignment of a
    > reference to a Function object to `window.onload' (or performing an
    > equivalent), or the `script' element to contain a function declaration and
    > the `onload' property of the `body' element to contain a call to that
    > function makes no real difference. The script is always tied to and
    > tailored to the markup.
    >
    > The real difference here is that the `onload' property is proprietary, and
    > both it and a standards-compliant equivalent would require feature-testing
    > for themselves, while the `onload' attribute is standardized as per HTML
    > 4.01 (and supported long before that) and requires no feature-testing on itself.
    >
    > PointedEars



    I have considered moving back to 4.01, but I get layout issues (DIV
    positioning).

    I'll find some midway between the two. Thanks for your reply.
     
    AndreHaupt, Dec 19, 2007
    #9
  10. AndreHaupt wrote:
    > [...] Thomas 'PointedEars' Lahn [...] wrote:
    >> The real difference here is that the `onload' property is proprietary, and
    >> both it and a standards-compliant equivalent would require feature-testing
    >> for themselves, while the `onload' attribute is standardized as per HTML
    >> 4.01 (and supported long before that) and requires no feature-testing on itself.
    >> [...]

    >
    > I have considered moving back to 4.01, but I get layout issues (DIV
    > positioning).


    Probably you have done something else wrong. Anyhow, XHTML 1.0 also
    provides the `onload' attribute, of course. So that alone is no sufficient
    reason to use HTML 4.01 in favor of XHTML 1.x; however, insufficient XHTML
    support, as I pointed out earlier, is.

    > I'll find some midway between the two.


    You can't have both. HTML-compatible XHTML is an illusion.

    > Thanks for your reply.


    You're welcome.


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Dec 19, 2007
    #10
    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. cmay
    Replies:
    0
    Views:
    1,164
  2. Pete Verdon
    Replies:
    6
    Views:
    582
    Pete Verdon
    Oct 27, 2006
  3. Ed Hauptman
    Replies:
    7
    Views:
    1,072
    Ed Hauptman
    Aug 7, 2009
  4. HolaGoogle
    Replies:
    1
    Views:
    118
    Ray at
    Oct 14, 2003
  5. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    601
    Martin Honnen
    Nov 4, 2004
Loading...

Share This Page