[Solved] Loading message


Yeah an old-school question!
This goes back to those days when we used to preload images…

Anyway, here’s some code. The magic is the “complete” property on the document.images collection (Image objects).

// setup a timer, adjust the 200 to some other milliseconds if desired
var _timer = setInterval("imgloaded()",200); 

function imgloaded() {
  // assume they're all loaded
  var loaded = true;

  // test all images for "complete" property
  for(var i = 0, len = document.images.length; i < len; i++) {
    if(!document.images[i].complete) { loaded = false; break; }
  }

  // if loaded is still true, change the HTML
  if(loaded) {
    document.getElementById("msg").innerHTML = "Done.";

    // clear the timer
    clearInterval(_timer);
  }
};

Of course, this assumes you have some DIV thrown in somewhere:

<div id="msg">Loading...</div>

2

solved Loading message