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'); });
Comments
Post a Comment