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:

  1. earliest: function call in script tag before closing body tag. dom is ready @ point (according google closure folks, , should know; i've tested on bunch of browsers).

  2. earlyish: jquery.ready callback (and shortcut forms).

  3. 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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -