Register  |  Login



Earn money by sharing your knowledge

Quomon shares its advertising revenue with contributing experts that answer questions effectively. Join our community to share your knowledge and earn an income as you go.

Question

Status: Closed Points: 50 Time: 19:35 - Oct 12, 2006  

jgivoni

Why doesn't OnLoad fire in Internet Explorer when script is loaded?

Consider this code:
<html>
<head>
 <title>test</title>
 <script src="test.js" onload="alert('ok')"></script>
</head>
<body>
</body>
</html>

We must presume that test.js exists of course.
According to MSDN the ONLOAD event should fire when the browser has loaded the object:
http://msdn.microsoft.com/workshop/autho...

(Notice the "Applies to: Script")

But it doesn't fire. At least not in my IE 6 browser.
(In FF 1.5 it does)

Anybody knows why? Or get different results?

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

Anpanman

Date:: Oct 13, 2006

Time:: 00:18

I didn't know this should be possible, but couldn't you use the <body onload="javascript: alert('ok');"> instead?

jgivoni

Date:: Oct 13, 2006

Time:: 14:45

I could, except that my html files are generated by php and the body part comes from one file, the scripts included on a given page from another. Therefore I would prefer that the loading of a given script incur the execution of that script. Actually the event would be: onload="init()".
Now you could say that why don't I just include that line "init();" as the first one in the actual script?
Beacuse maybe I want to include the script without executing the init() in some cases.

Don't worry, there are plenty of other solutions, I just would like to know if anyone had knowledge about this specific issue.

I'll keep the question open...

nhinds

Date:: Nov 01, 2006

Time:: 00:35

I would stay away from tags like that, and use something like this:
if (window.addEventListener) window.addEventListener('load',init,false);
else if (document.addEventListener) document.addEventListener('load',init,false);
else if (window.attachEvent) window.attachEvent('onload',init);
else {//Older browsers only
if (typeof window.onload=='function') {
var oldload=window.onload;
window.onload=function(){
oldload();
init();
}
} else window.onload=init;
}

jgivoni

Date:: Nov 06, 2006

Time:: 02:04

nhinds, why would you stay away from tags like that?

And another thing; at what point and how do you suggest to run the script you propose?

nhinds

Date:: Nov 06, 2006

Time:: 21:44

I avoid tags like onload because, in my opinion, they just pollute the markup (although that can be taken too far). Just throw that code in at the end of the javascript file you're including, or in its own script tag below the script with init in it

jgivoni

Date:: Nov 21, 2006

Time:: 12:32

But nhinds,

if I put it in a script tag below the one that loads the script - wouldn't that just pollute the markup even more?

And if I put it inside the script itself, then I know that the script is already loaded, and I no longer need to attach any onload event to it!

Finally, my original question still stands uncommented:
Why doesn't the even fire - even though the documentation provided by the manufacturer states that it should?
I can see three posibilities so far:
1) I am reading the documentation wrong
2) I am reading the wrong documentation
3) It is a bug (may be limited to certain versions)

haris

Date:: Aug 20, 2007

Time:: 00:35

It occurs in specific conditions which are unspecific. I create a simple HTML page and add an alert in body onload, it gives the alert but when I do the same in my ASP.NET application page (it has a lot of code) it does not work. May be some other javascript call falsifies it. Occurs only in IE 6.0. FF, Opera work well. If you find any solution, please post it to www.burqe.com contact us so it may reach me and I need it.

uiqzfarkrypq

Date:: Nov 24, 2008

Time:: 12:48

Here is one solution: http://somanyschemes.com/2008/11/23/repl...

Question Answered

This question has been closed, and points have been rewarded to the following experts:

jgivoni: 50

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top internet Experts

View More

Rank

Expert

Points

1.

nidhi

1355

2.

LAGM

735

3.

rcastagna

414

4.

oracleofDelphi

272

5.

admin1

250

6.

jgivoni

125

7.

john4

100

8.

nhinds

75

9.

PeterNZ

65

10.

multani.sarbjit

50

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es