cofcmgr
asked on
javascript question on converting body onload to window.onload
a quick one.....how do i convert this body onload to a window.onload?
<body onload="nextCount('counter ');">
thought it would be easy enough, but getting hung up on how to pass the "counter" parameter?
<body onload="nextCount('counter
thought it would be easy enough, but getting hung up on how to pass the "counter" parameter?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@frindo that is not correct.
eventhandler = function
or
eventhandler = something returning a function
In you case, the nextcount is evaluated immediately and the window.onload set to the result of the evaluation.
KiranVJ has the correct version
eventhandler = function
or
eventhandler = something returning a function
In you case, the nextcount is evaluated immediately and the window.onload set to the result of the evaluation.
KiranVJ has the correct version
Oh, my mistake.
So could you just put "nextCount('counter');" at the top of the page and it would just as well?
So could you just put "nextCount('counter');" at the top of the page and it would just as well?
Agreed with KiranVJ solution
No, you could put it at the very bottom of the page in a script before </body> and it would MORE OR LESS work the same.
onLoad is triggered in IE at least more or less when the page and its content has loaded. It might trigger well after the end body tag has rendered but at least the html and dom objects on the page are there
The best is the function assigned to window.onload either directly
function initPage() {
nextCount('counter');
}
window.onload=initPage; // notice the lack of ()
or as already suggested, anonymously :
window.onload = function() {
nextCount('counter');
}
points to Kiran
onLoad is triggered in IE at least more or less when the page and its content has loaded. It might trigger well after the end body tag has rendered but at least the html and dom objects on the page are there
The best is the function assigned to window.onload either directly
function initPage() {
nextCount('counter');
}
window.onload=initPage; // notice the lack of ()
or as already suggested, anonymously :
window.onload = function() {
nextCount('counter');
}
points to Kiran
hi mplungjan,
1 doubt i just got.
window.onload = function() {
functionA('parameter');
}
window.onload = function() {
functionB('someOther_param eter');
}
will the 2 functions be executed or just the second one.
kiranvj
1 doubt i just got.
window.onload = function() {
functionA('parameter');
}
window.onload = function() {
functionB('someOther_param
}
will the 2 functions be executed or just the second one.
kiranvj
Just the second one
You need
window.onload = function() {
functionA('parameter');
functionB('someOther_param eter');
}
You need
window.onload = function() {
functionA('parameter');
functionB('someOther_param
}
thats good, Thanks
window.onload=nextCount('c
Also, there is no functional difference between the two methods so the only reason you would convert from a body onload to a window.onload is for viewing purposes (you don't want to mix your javascript with your HTML)