Strange Onload problem

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

    Strange Onload problem

    Hi there,

    I have a php-generated page which can have a variety of layouts, depending
    on a lot of things. But every layout has the same <head> and <body>
    so i cannot put an onload in the <body> tag.

    My problem:
    I use the following code inside the body, which should be cross-browser:

    if (window.attachE vent) {
    window.attachEv ent('onload', goNL());
    } else if (window.addEven tListener) {
    window.addEvent Listener("load" , goNL(), false);
    } else {
    window.onload = goNL();
    };

    function goNL(){
    document.getEle mentById('en'). style.display = "none"
    document.getEle mentById('de'). style.display = "none"
    document.getEle mentById('nl'). style.display = "inline"
    };

    When i call goNL() bij link <a href="javascrip t:goNL()">link</a> it works,
    but why won't it work by itself????

    Please lend me a hand!

    Thanks & Greetings Knoak
  • Martin Honnen

    #2
    Re: Strange Onload problem



    knoak wrote:

    [color=blue]
    > I use the following code inside the body, which should be cross-browser:
    >
    > if (window.attachE vent) {
    > window.attachEv ent('onload', goNL());
    > } else if (window.addEven tListener) {
    > window.addEvent Listener("load" , goNL(), false);
    > } else {
    > window.onload = goNL();
    > };[/color]

    You should pass/assign the function goNL and not call it as you do above
    so you want

    if (window.attachE vent) {
    window.attachEv ent('onload', goNL);
    } else if (window.addEven tListener) {
    window.addEvent Listener("load" , goNL, false);
    } else {
    window.onload = goNL;
    };



    --

    Martin Honnen

    Comment

    Working...