469,343 Members | 5,478 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

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.attachEvent) {
window.attachEvent('onload', goNL());
} else if (window.addEventListener) {
window.addEventListener("load", goNL(), false);
} else {
window.onload = goNL();
};

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

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

Please lend me a hand!

Thanks & Greetings Knoak
Jul 23 '05 #1
1 1045


knoak wrote:

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

if (window.attachEvent) {
window.attachEvent('onload', goNL());
} else if (window.addEventListener) {
window.addEventListener("load", goNL(), false);
} else {
window.onload = goNL();
};


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

if (window.attachEvent) {
window.attachEvent('onload', goNL);
} else if (window.addEventListener) {
window.addEventListener("load", goNL, false);
} else {
window.onload = goNL;
};

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Robert Misiorowski | last post: by
4 posts views Thread by David Virgil Hobbs | last post: by
10 posts views Thread by berg | last post: by
14 posts views Thread by Mario | last post: by
2 posts views Thread by laredotornado | last post: by
4 posts views Thread by Nate Murray | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.