Is there any trick how to start a function in javascript, which starts when the page is completely loaded?
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).
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(){
...
});
$( window ).bind( 'load', function()
{
//your code in here
} );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With