423,688 Members | 1,864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

why is onload not working?

P: 3
Does anyone know of possible reasons why onload might not be working? It's gotta be the most pathetic question ever, it's doing my head in!! I've done this a dozen times, but on this one, nothing! I just can't see what the problem might be.

Here's the background:

Initially the idea was to run a js function using

Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.   myfunction();
  3. }
in an external js script which is linked to in the common header (that link works fine as other functions in the same script run as and when they're supposed to). Wouldn't do anything, but I've had that problem elsewhere before and while I never knew why it wouldn't work for me, back then I managed to fix it by using

Expand|Select|Wrap|Line Numbers
  1. <body onload="myfuntion();">
instead.

So I tried the same again this time - but it's still not working. It's not the function I'm calling, it works fine when I call it other ways - but I need it onload.

So I thought, let's drill down to the most basic thing ever:

Expand|Select|Wrap|Line Numbers
  1. <body onLoad="alert('hello world!')">
and that's is not working either! Nor some variation thereof, like

Expand|Select|Wrap|Line Numbers
  1. <body onload="javascript: alert('hello world!');">
What the HECK? Any and all suggestions what I might try, please?

Thanks!
Jan 13 '10 #1
Share this Question
Share on Google+
4 Replies


Dormilich
Expert Mod 5K+
P: 8,639
do you have a link I can look at?
Jan 13 '10 #2

P: 3
In fact, I just realised: onload not working seems to be a problem for Firefox - just thought of looking at it in IE7, I get hello'd!

Dormilich, pm'ing you the link. Thanks.
Jan 13 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
the problem is you have too many onload events. there is only one allowed (I’ve had this too)

You should be able to overcome this with addEventListener() (it allows for more that function to be executed for one event) but IE will show there it’s strength in failing.

PS. sensible call: window.onload = menuSelect;
Jan 13 '10 #4

P: 3
Ahaaa! Of course. I'd completely forgot about the other onload I do. Brill, thanks so much, Dormilich! :-)
Jan 14 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.