473,372 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

Problem Pre-Loading Images Using Javascript

I am trying to get the following code to pre-load some images before re-dirrecting the user. The problem is that the onError event gets called for all of the images immediately. I've tripple checked that the images do in fact exist at the specific url, so I can't figure out why the onError is being called. The script is currently posted on http://www.mkcustomdesign.com/index.html.

<script type="text/javascript">

var imagesToLoad = 0;
var imagesLoaded = 0;

function loadImages(){

images = new Array("loading.jpg", "row1.jpg", "index_02.jpg", "index_03.jpg", "index_03.jpg", "index_04.jpg", "index_05.jpg",
"index_06.jpg", "mkcustom.jpg", "spacerrow.jpg", "box_1_1_table.jpg", "box_1_2_chair.jpg",
"box_1_3_bed.jpg","side_1_right.jpg", "side_1_left.jpg", "row3.jpg", "side_2_left.jpg",
"box_2_1_cabinets.jpg" , "box_2_2_railing.jpg", "box_2_3_misc.jpg", "side_2_right.jpg",
"bottom2.jpg" );

imagesToLoad = images.length;
for(i = 0; i < images.length; i++){
image = new Image();
image.onLoad = imageLoaded();
image.onError = error("images/" + images[i]);
image.src = "images/" + images[i];


function error(image){
alert('error with ' + image);

function imageLoaded(){
document.getElementById('loading').innerHTML = 'Loaded ' + imagesLoaded + "/" + imagesToLoad + ' images ';
if(imagesLoaded == imagesToLoad){
//document.location = "main.html";

Apr 25 '07 #1
1 1868
210 100+
Expand|Select|Wrap|Line Numbers
  1. image.onLoad = imageLoaded();
  2.         image.onError = error("images/" + images[i]);
An event handler is passed as a function address not a function call. I haven't tested this but try it:
Expand|Select|Wrap|Line Numbers
  1. image.onLoad = imageLoaded;
  2. image.onerror = new Function("error('images/' + images[i])") ;
As for the loaded images indicator, you may not always get onload events when testing locally.
Apr 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Dan | last post by:
I'm trying to create a menu in javascript. I've created the bitmaps with text over the top of them. The problem i'm having is that the positions aren't correct. If I wrap the code in PRE tags,...
by: Alan Illeman | last post by:
How do I set several different properties for PRE in a CSS stylesheet, rather than resorting to this: <BODY> <PRE STYLE="font-family:monospace; font-size:0.95em; width:40%; border:red 2px...
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to...
by: TomB | last post by:
Hello all, On the page located at http://deimos.curious.be/~dusk/lyrics.php#gotn I have put the lyrics text inside <pre> elements so that the UA renders the linebreaks in the code. Because...
by: Leszek | last post by:
I have a form with 5 dropdown lists I want to put all selected values to an array called $data so i wrote sometthing like this: for(i=0;i<5;i++){ echo"<select name=\"\$data\">"; echo"<option...
by: Leszek | last post by:
Hi. I'm using <pre><?php print_r($_POST); ?> </pre> and i'm getting this: Array (
by: effendi | last post by:
I am trying to figure this out. I have the following fuction, which takes value for a hidden field in a form and display the values on the browser. The code work fine except in Firefox/Opera,...
by: Vadim Guchenko | last post by:
Hello. I'm using the following code: <html> <head> <style type="text/css"> pre {display: inline;} </style> </head>
by: alain | last post by:
Hi, I have a problem with closures. I am trying to implement yet another design by contract decorator which would look like the following: <pre> def contract(f): def newf(*args, **kw):...
by: Kim | last post by:
Hi, why doesn't this work inside a loop, gives me the wrong "kontrollnummer" (increases it as the loop goes on) <% Dim kontrollnummer Dim raknare Dim Summa Dim referens referens =...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.