7

When using $(document).ready(functioon(){alert("Loaded.")}); it pops up the alert box that says "Loaded." even before the page has fully loaded (in other words there're loading still going on like images).

Any thoughts?

Propeller
  • 2,415
  • 6
  • 33
  • 48
  • ready() executes for the page is loaded, which means the pure html text. If you'd like to check if all images is loaded, you may need to write more codes on some image event handlers I guess – hago Mar 09 '12 at 08:27
  • In case you really want to make sure all assets are loaded you'll have to listen for each one of them. You can do something like this: http://stackoverflow.com/questions/9332167/preload-audio-files-event - the code in the answer works pretty fine – m90 Mar 09 '12 at 08:30

4 Answers4

14

$(window).on('load', function() {
    //everything is loaded
});


Jacob van Lingen
  • 8,337
  • 7
  • 43
  • 74
Sudhir Bastakoti
  • 97,363
  • 15
  • 155
  • 158
4

Try out .load() instead.

$(document).load(function () {
    alert('Loaded');
}

The load event is sent to an element when it and all sub-elements have been completely loaded. http://api.jquery.com/load-event/

0

Using javascript

   window.onload = function () { alert("loaded"); }
Gowri
  • 16,119
  • 25
  • 97
  • 158
0

You can read more about it here. https://github.com/codef0rmer/learn.jquery.com/blob/master/content/jquery-basics/document-ready.md

codef0rmer
  • 10,079
  • 9
  • 48
  • 76