javascript - Trigger event on body load complete js/jquery -
i want trigger 1 event on page load complete using javascript/jquery.
is there way trigger event or call simple function once page loading completes.
please suggest folks if reference.
everyone's mentioned ready
function (and shortcuts), earlier that, can put code in script
tag before closing body
tag (this yui , google closure folks recommend), this:
<script type='text/javascript'> pageload(); </script> </body>
at point, above script tag available in dom.
so options in order of occurrence:
earliest: function call in
script
tag before closingbody
tag. dom is ready @ point (according google closure folks, , should know; i've tested on bunch of browsers).earlyish:
jquery.ready
callback (and shortcut forms).late, after all page elements including images loaded:
window
onload
event.
here's live example: http://jsbin.com/icazi4, relevant extract:
</body> <script type='text/javascript'> runpage(); jquery(function() { display("from <tt>jquery.ready</tt> callback."); }); $(window).load(function() { display("from <tt>window.onload</tt> callback."); }); function runpage() { display("from function call @ end of <tt>body</tt> tag."); } function display(msg) { var p = document.createelement('p'); p.innerhtml = msg; document.body.appendchild(p); } </script>
(yes, have used jquery display
function, starting non-jquery template.)
Comments
Post a Comment