|
I didn't know this should be possible, but couldn't you use the <body onload="javascript: alert('ok');"> instead?
|
|
Expert:
|
Anpanman
|
|
Date:
|
Oct 13, 2006
|
|
Time:
|
00:18
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
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...
|
|
Expert:
|
jgivoni
|
|
Date:
|
Oct 13, 2006
|
|
Time:
|
14:45
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
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;
}
|
|
Expert:
|
nhinds
|
|
Date:
|
Nov 01, 2006
|
|
Time:
|
00:35
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
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?
|
|
Expert:
|
jgivoni
|
|
Date:
|
Nov 06, 2006
|
|
Time:
|
02:04
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
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
|
|
Expert:
|
nhinds
|
|
Date:
|
Nov 06, 2006
|
|
Time:
|
21:44
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
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)
|
|
Expert:
|
jgivoni
|
|
Date:
|
Nov 21, 2006
|
|
Time:
|
12:32
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
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.
|
|
Expert:
|
haris
|
|
Date:
|
Aug 20, 2007
|
|
Time:
|
00:35
|
|
|
|
Votes: Good (0) | Bad (0) Login to rate this answer
|
|
|
|
|
|
|
This question has been answered, and points have been rewarded to the following experts:
You're welcome however to comment or give additional information or if you wish, you have the ability to write an Answer Summary for this question by clicking on the "Answer Summaries" Tab.
|
|