Problem with preloading images on IE on Windows XP

J

Julie

Hi,

I'm trying to change images on a website without reloading the whole
page and use the following code to preload the images:

var preloadFlag = false;
function preloadImages() {
if (document.images) {
pic_moon2_click = newImage("images/moonpic2.jpg");
pic_moon3_click = newImage("images/moonpic3.jpg");
pic_moon4_click = newImage("images/moonpic4.jpg");
one_click = newImage("images/1.gif");
two_click = newImage("images/2r.gif");
three_click = newImage("images/3r.gif");
flour_click = newImage("images/4r.gif");
two_caps_click = newImage("images/mooncaps2.gif");
three_caps_click = newImage("images/mooncaps3.gif");
four_caps_click = newImage("images/mooncaps4.gif");
preloadFlag = true;
}
}


to change the images I use this code:

function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src =
changeImages.arguments[i+1];
}
}
}

when I click on the field that should make the images change (images
in three places are supposed to change at the same time, including the
one I'm clicking) I hand over two variables for each imagefield, the
name of the image tag that I want to change and the source of the new
image, I separate each group of two variables by a comma.

On my mac and various other platforms it seems to work fine but on
certain computers with Windows XP (IE6), not on all, the new images
don't load, but after clicking the button the image td is empty. If I
right click into the td and click on "Load Image" the right image
loads.

I tried to look at the page locally and then it all works fine even on
XP. So I thought it must have something to do with preloading the
images.

After that I tried a different code that doesn't use a preload
function but for some reason that didn't work either.

I have no idea what else to try... maybe someone here can help me :)
 
I

Ivo

I'm trying to change images on a website without reloading the whole
page and use the following code to preload the images:

var preloadFlag = false;
function preloadImages() {
if (document.images) {
pic_moon2_click = newImage("images/moonpic2.jpg");

Where did you pick up this newImage thing? There is no such thing in
Javascript. There is the Image object, which takes two optional parameters
for its dimensions, not its source. You need to set the src in a separate
statement.
What you want to do is this:

if (window.Image) {
pic_moon2_click = new Image(); // note the space after "new"
pic_moon2_click.src = "images/moonpic2.jpg";
etc.

HTH
Ivo
 
J

Julie

Where did you pick up this newImage thing? There is no such thing in
Javascript. There is the Image object, which takes two optional parameters
for its dimensions, not its source. You need to set the src in a separate
statement.
What you want to do is this:

if (window.Image) {
pic_moon2_click = new Image(); // note the space after "new"
pic_moon2_click.src = "images/moonpic2.jpg";
etc.

HTH
Ivo

I have a function called newImage

function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}

that's why I think I don't need to set the src seperately here.
Do you think some platforms have a problem with that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top