jquery - How to append to window.onload? -


i have function, foo, add window.onload problem there function, bar, set window.onload. how can both functions attached. have no access change logic of how bar added window.onload therefore can’t use paradigm addevent(…) . following work in cases?

<script> $(window).load(foo(){ //my code here }); </script>  //lots of html //potentially happens before or after above script  <script> window.onload = bar(); otherfunction(){ //other function code here }; </script> 

this non-issue since you're using jquery. can call $(window).load(...) multiple times , won't stomp out previously-bound event handlers.

this function takes anonymous function parameter, executed once load event fired. e.g.

$(window).load(function() {alert('the window has loaded');}); 

jquery documentation of .load() handler: https://api.jquery.com/load-event.

for reference, equivalent "vanilla" js use window.addeventlistener.


update

instead of .load event, use .on('load,':

$(window).on('load', function() { alert('this better'); }); 

see https://stackoverflow.com/a/37915907/361842 more.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -