Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery - if page loaded

Is there any trick how to start a function in javascript, which starts when the page is completely loaded?

like image 320
njaknjak Avatar asked Mar 17 '11 22:03

njaknjak


People also ask

What is the page load event in jQuery?

The load event occurs when a specified element has been loaded. This event works with elements associated with a URL (image, script, frame, iframe), and the window object. Depending on the browser, the load event may not trigger if the image is cached (Firefox and IE).


2 Answers

If you mean when the HTML document has loaded, use the ready event:

$(document).ready(function(){
  ...
});

Or the shorthand:

$(function(){
  ...
});

If you mean when the page including all style sheets, scripts, images and whatnot has completed loading, use the load event:

$(window).load(function(){
  ...
});
like image 134
Guffa Avatar answered Oct 07 '22 10:10

Guffa


$( window ).bind( 'load', function()
{
    //your code in here
} );
like image 37
JAAulde Avatar answered Oct 07 '22 10:10

JAAulde