View Full Version : problem with preloader (Array issue?)

08-19-2002, 08:16 PM
My preloader works great except it continues to load past 100%. How can I get it to stop. My pop up prompt to continue to next page appears at the right time but the percentage counter goes beyond 100%. How do I get it to stop the percentage counter it has loaded all the images.



var pics = new Array ("DBCpublic/images to use/horiz linegrey.jpg", "DBCpublic/images to use/spider.jpg", "DBCpublic/images to use/images alt home/bnrie.gif", "DBCpublic/images to use/images alt home/greyline.jpg", "DBCpublic/images to use/images alt home/segment2.jpg");

var url = "DBCpublic/home.htm";

var doConfirm = true;

var canSkip = true;

var imgObjs = new Array(pics.length);
var loaded = 0;
var total = pics.length;
var cPercent = 0;

var barLayer = null;
var percentLayer = null;
var statLayer = null;
var doneMsgLayer = null;

function getLayer(layerID) {
if (document.getElementById)
return document.getElementById(layerID);
else if (document.all)
return document.all[layerID];
return null;

function updateBar() {
statLayer.innerHTML = "<font face=\"Arial\" color=\"#cccccc\" size=\"2\">" +loaded+ "/" +total+ "</font>";
var percent = Math.round(loaded/total * 100);
if (cPercent != percent)
cPercent = percent;
barLayer.style.width = (cPercent*3.5) +"px";
percentLayer.innerHTML = "<font color=\"#cccc99\"><B>" +cPercent+ "%</B></font>";
if (loaded == total)
doneMsgLayer.innerHTML = "<a href=\"javascript:done()\"><font face=\"Arial\" color=\"#cccc99\" size=\"2\">enter site (click here)</font></a>";
if (doConfirm && confirm("files have loaded, continue to next page?"))

function startLoading() {
if (document.getElementById || document.all)
barLayer = getLayer("bar");
percentLayer = getLayer("percent");
statLayer = getLayer("stat");
doneMsgLayer = getLayer("doneMsg");
if (canSkip)
doneMsgLayer.innerHTML = "<a href=\"javascript:done()\"><font color=\"#cccc99\" size=\"2\" face=\"Arial\">skip pre-loading</font></a>";
for (i=0; i<pics.length; i++)
imgObjs[i] = new Image();
imgObjs[i].onload = imgLoaded;
imgObjs[i].onerror = imgFailed;
imgObjs[i].src = pics[i];
alert("You are likely running an older browser which is not compatible with this preloading script. Maybe it is time to update your browser.\n\nProgram is skipping preloading.");

function done() {

function imgFailed() {
alert("The following image failed to load, probably a broken link:\n" +this.src+ "\nPlease contact the webmaster to report error. The program will skip this file now.");

function imgLoaded() {


08-19-2002, 10:58 PM
What browser are you using? It seems to work OK for me, I created the body, added 4 div's and at 100% I was prompted. It did not seem to keep loading in IE 5.5, Mozilla 1.0, or NS 6.1. I was able to watch as I retrieved 5 large pics off of an external site (DU Meter), and it did not appear that it continued after the dialog came up.

The for loop that is in control of the iterations seems to work properly and logically. for (i=0; i<pics.length; i++)

What behavior are you seeing? Does the 100% display go beyond 100% -> 120%?


08-19-2002, 11:08 PM
I am runninig IE 6. The problem I am having is that if you do not accept the load next page prompt the percentage counter continues to load. I have seen it go as far as 140%. When I call the images by "image name.jpg" it won't locate the image, but the percentage counter stops at 100%. If I call the images by "folder/image name. jpg" it can locate the image, but the counter will go past 100%. When I check my cache it has loaded the correct number of images (134 total images - all listed in the array) even though the counter indicates that it is still loading. Are the images perhaps loading agian?

Thank you so much for your reply - this has been bugging me for days.

08-20-2002, 05:18 PM
The only way I can imagine the images loading again would be if the images took more space than the browser had cache for.

You could I suppose check for 100 cPercent and then stop processing, or skip processing to the done() state.

That would keep it from hitting 100+%

I still can't duplicate the problem, so I can't really pin point what is going wrong.


08-20-2002, 09:44 PM
Thank you for your help. Perhaps if you check out the website link below you will see it happen. It definately creeps over 100% if you do not immediatly select okay on the load page popup or if you select cancel. I have tried to insert a command to hide or stop the percentage counter, but I seem to only create errors.
Again thank you for taking the time to help me out.


08-20-2002, 10:26 PM
Yeah! I finaly got it. The preloader did not like an animated GIf I was preloading. As soon as I took it out it worked. If any one has any advise on how to correctly preload an animated gif I would love to know