Forum Moderators: open

Message Too Old, No Replies

Weird cloneNode .src error?

a gif file name p00001.gif causes error in script

         

trifi

6:52 am on Dec 3, 2003 (gmt 0)

10+ Year Member



A miracle if someone knows the exact cause of this problem!
I am changing an image on resize, onLoad, etc. The image is in a table with 6 other images inside a div. I place all the images in an array, then clone the images(true) then set the clone.src to the original image.src(I do this so I will always set my height and width ratio to the original image size and not the one set on resize, this stops image from becoming distorted). Now when I change the src on image name p00001.gif it alters the size(before I do with javascript).
Also I wanted to avoid creating a new element because I am using the same function to load a larger version of the image into a pop.window(different frame).
Changing the .gif name of another file to p00001 also cause error as well as changing src. I tried many names similar to p00001.gif an none cause this error. I even open the .gif in an editor to see if something was wrong or a gif had a header with some paramaters causing this error.
For now I've only tested it on IE. Below is the code.
Note:to clear up the code I do the ratio of width to screen width to see which is bigger width or heigh ratio. I then size the image according to with is bigger w or h ratio.

function setDivCur(el)
//el is id of div containing images
{

var imgAry=document.getElementById (el.id).getElementsByTagName('img');

for (i=0; i<imgAry.length;i++)
{

var nImg=imgAry[i].cloneNode(true);

nImg.src=imgAry[i].src;

var d1=(sW*.12)/nImg.width;
//sW is document window width
var d2=(sH*.12)/nImg.height;
//sH is document window height
var myR=(d1<d2)?d1:d2;
='+nImg.height+'width= '+nImg.width);
nImg.width=myR*nImg.width;
nImg.height=myR*nImg.height;
imgAry[i].parentNode.replaceChild(nImg,imgAry[i]);

}

}

Anyone have any clue, I searched the net and found nothing.

HocusPocus

3:05 pm on Dec 3, 2003 (gmt 0)

10+ Year Member



Not totally sure what you are asking, but I believe that Image.width, .height is read only. Its set by the WIDTH attribute of the IMG tag. I don't think Javascript can be used to find the dimensions of an image.

Hope this helps

trifi

4:49 pm on Dec 3, 2003 (gmt 0)

10+ Year Member



thanks hocus for replying but you can set the width and height of an object this being the img tag, you cannot change the height width of the img src. for instance you cannot create an image element upload an image and set the width and height, however I clone the img tag then set .src of the cloned image to the original. My problem is p0000.gif causes an error after cloning(as stated above).