Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

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?
0
cofcmgr
Asked:
cofcmgr
  • 3
  • 3
  • 2
  • +1
1 Solution
 
frindoCommented:
just add the following between the script tags at the top of the page:

window.onload=nextCount('counter');

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)
0
 
Kiran Paul VJComputer EngineerCommented:
or try this
<script language="javascript">
window.onload = function() {
                                                 nextCount('counter');
                                             }
</script>


hope this helps
kiranvj
0
 
Michel PlungjanIT ExpertCommented:
@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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
frindoCommented:
Oh, my mistake.

So could you just put "nextCount('counter');" at the top of the page and it would just as well?
0
 
KhoiNqqCommented:
Agreed with KiranVJ solution
0
 
Michel PlungjanIT ExpertCommented:
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
0
 
Kiran Paul VJComputer EngineerCommented:
hi mplungjan,

1 doubt i just got.

window.onload = function() {
  functionA('parameter');
}

window.onload = function() {
  functionB('someOther_parameter');
}

will the 2 functions be executed or just the second one.

kiranvj
0
 
Michel PlungjanIT ExpertCommented:
Just the second one

You need



window.onload = function() {
  functionA('parameter');
  functionB('someOther_parameter');
}

0
 
Kiran Paul VJComputer EngineerCommented:
thats good, Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now