Odd javascript problem under Safari


macrumors 6502
Original poster
Sep 14, 2005
This is a strange one! Have a look at the following piece of code-

function loadimage() { //loads clicked image into window
document.images['largeimage'].src = ("../images/"+ clickedimage +"_"+ x +".jpg");

And a bit further down:

<img src="../gfx/pleasewait.gif" name="largeimage">

The variable 'clickedimage' is the filename of the image, and 'x' refers to a suffix that gives each image a number in the sequence.

This piece of code basically loads an image into a new window, depending on what was clicked in another window, and then once there in the new window, the user can scroll through the images one by one by clicking forward and back buttons. The next image in the sequence replaces the last one. The initial gif image just sits there playing as a preloader until the images in the sequence are downloaded. It works perfectly in most browsers (IE, Mozilla, Opera) but not Safari.

Under Safari, the images in the sequence get stretched to fit the same dimensions as whatever the first one had. In other words if the first image is a landscape format shot, and the next one is portrait, the portrait one will be stretched outwards to match the size of the landscape. I'm not sure why this happens, nor how I might get around it. The images are jpegs and are all the same height, but different widths.

Have a look at www.chrisbracewell.com and click on one of the images in the strip, and you'll be able to see what I mean. Feel free to have a look at the source code in the pop up window for more information.

Any ideas or suggestions very welcome!