Click to See Complete Forum and Search --> : AppendChild img on IE5 for Mac


marek_walford
06-06-2003, 09:39 AM
Hi,

Has anybody experienced problems using appendChild to add an image to a table cell. I can't isoalte the problem as I have successfully added an individual image but adding a series of images in a loop causes the machine to hang. I'll try and narrow it down but does anybody have any suggestions?

I'm using IE5.2.2 for Mac OS X

The code I'm using is:

var oImg = document.createElement("IMG");
oImg.width = 11;
oImg.height = 11;

if(value == true) {
oImg.setAttribute("src", IMG_PATH + "tick.gif");
}
else {
oImg.setAttribute("src", IMG_PATH + "cross.gif");
}

oCell.appendChild(oImg);


Cheers,
Marek

Khalid Ali
06-06-2003, 10:13 AM
Did you test your code on NS6+/Mozilla browsers?

Reason is that IE on Mac is buggggy as hell( since its fairly new browser for MacOS)

marek_walford
06-06-2003, 10:20 AM
>Did you test your code on NS6+/Mozilla browsers?

Yes and all is fine.

>Reason is that IE on Mac is buggggy as hell( since its fairly >new browser for MacOS)

Tell me about it! My company in their infinite wisdom insist on supporting Macs so I have to get it to work.

I am dynamically creating tables so I have two loops; the outer one creates the rows and the inner one creates the cells. The problem lies in appending images to the cells. It appears that IE hangs after creating the 10th row. Rows 0-9 work fine but as soon as I try and add the next row the browser hangs requiring a "Force quit".

Cheers,
Marek

Khalid Ali
06-06-2003, 10:40 AM
post your full code..
I have seen in some cases if you use object.innerHTML it works allot better in IE as compare to appendChild
what you can possibly do is create all images in strings for IE and then use innerHTML for a that cell to put that in that cell.

marek_walford
06-06-2003, 10:46 AM
The following code reproduces the problem on my machine. Using innerHTML probably would work but I was hoping to have a nice OO script.

<html>
<head>

<SCRIPT language="JavaScript">

function start()
{
var oDiv2 = document.createElement("DIV");
document.body.appendChild(oDiv2);

var oTable2 = document.createElement("TABLE");
oDiv2.appendChild(oTable2);
oTable2.cellPadding = 0;
oTable2.cellSpacing = 0;

var oTableBody2 = document.createElement("TBODY");
oTable2.appendChild(oTableBody2);

for(var x = 0; x < 10; x++)
{
var oRow = document.createElement("TR");
oTableBody2.appendChild(oRow);

for(var i = 0; i < 10; i++)
{
var oCell = document.createElement("TD");

var oImg = document.createElement("IMG");
oCell.appendChild(oImg);
oRow.appendChild(oCell);
}
}
}

</script>




</head>
<body>

<script language="JavaScript">
start();
</SCRIPT>

</body>
</html>

Khalid Ali
06-06-2003, 12:13 PM
I could not re produce the error when useing the limit

for(var x = 0; x < 20; x++)

for(var i = 0; i < 20;i++)

?????

It worked and printed the images

Here is the link...

http://68.145.35.86/temp/ImageLoadingProblem_marek_walford.html

marek_walford
06-09-2003, 04:06 AM
Sorry, I can't get the link to your page to work - "Page cannot be displayed" error. Did you get it to work on IE5.2.2 for Mac OS x because it does work fine on a PC.

marek_walford
06-09-2003, 04:17 AM
Sorry, I can't get the link to your page to work - "Page cannot be displayed" error. Did you get it to work on IE5.2.2 for Mac OS x because it does work fine on a PC.

marek_walford
06-12-2003, 05:46 AM
I've since discovered that the source of the problem is not with the appendChild as the same problem occurs if I use innerHTML.

The problem seems to be to do with dynamically adding IMG tags over a certain number. Much more than about 12 (it varies) causes IE to hang.

I've given up and added the image as a background image of the cell and now all is fine.