javascript - Image Preloader Getting Stuck in IE8 -


i've searched high , low solution problem, extremely grateful can shed light.

below simplified version of function used preload 25 images. works fantastically in ie9-10 , in chrome.

in ie8 gets partway through loading images (e.g. 10/25) stops. if refresh browser continue load images, taking ~3 refreshes complete. should not necessary!

on odd occasion succeed in loading images in 1 go. tried avoid using .load() i've read can problematic in ie yet here same! tried using different images rule out image format cause.

i'm looking either fix below code or better solution if has one.

many thanks.

function loadallimages() {     var imgarray = [ //image srcs stored in array     'imgsrc01.jpg',     'imgsrc02.jpg',     'imgsrc03.jpg',     ...     'imgsrc25.jpg'];      var nofinalimg = imgarray.length - 1;      var = -1;     var waittime = 10000;      if (imgarray.length === 0) {         return;     } else {         loadimage();     };      function loadimage() {         i++;         var url = imgarray[i];         var img = new image();         var timer;          img.src = url;         img.id = "thumb" + i;          // image loaded         if (img.complete || img.readystate === 4) {                     //call image loaded function                     console.log(i + "/" + nofinalimg);              //equivalent loop next             if (i !== nofinalimg) {                 loadimage();             };             // image not loaded         } else {             // handle 404 using settimeout set @ waittime             timer = settimeout(function () {                 if (i !== nofinalimg) {                     loadimage();                 };                 $(img).unbind('error load onreadystate');             }, waittime);             $(img).bind('error load onreadystatechange', function (e) {                 cleartimeout(timer);                 if (e.type !== 'error') {                     //call image loaded function                     console.log(i + "/" + nofinalimg);                  };                 if (i !== nofinalimg) {                     loadimage();                 };             });         };     }; }; 


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -