472,127 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

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 1079


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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.