468,107 Members | 1,507 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,107 developers. It's quick & easy.

Problem with preloading images on IE on Windows XP

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[i]].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 :-)
Jul 23 '05 #1
2 1672
Ivo
"Julie" wrote
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
Jul 23 '05 #2
> 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?
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Fabian | last post: by
6 posts views Thread by michaaal | last post: by
2 posts views Thread by windandwaves | last post: by
40 posts views Thread by Geoff Cox | last post: by
3 posts views Thread by giladg22 | last post: by
2 posts views Thread by sachaburnett | last post: by
7 posts views Thread by Keith Hughitt | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.