FlyingCat FlyingCat -4 years ago 79
Javascript Question

How to detect if the browser is loading

I am trying to show a loading image when a users click a link that will show a large image in the same page.

I was wondering what's best way to detect image loading WHILE the page has been loaded already (so window.onload() doesn't work).

Answer Source

Load the image with JavaScript and then you can use the image's onLoad attribute:

Image1 = new Image();
Image1.src = 'photo.gif';

/* Code here to display loading hour glass etc */

Image1.onload = function() {
                           /* Image has loaded here */
                        }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download