| re: inserting image into table cell using dom distorting
RobG wrote:[color=blue]
> Andrew Poulos wrote:
>[color=green]
>> If I put the code into a loop to create 4 separate tables. In IE, the
>> first, second and fourth images are not distorted whereas the third
>> image is:[/color]
>
>
> It should only create one table and image:
>[color=green]
>>
>> var numTables = 4;
>> for (var i = 0; i<numTables; i++) {[/color]
>
> Here you initialise i as a counter for your for loop.
>[color=green][color=darkred]
>>> //create table
>>> var t = document.createElement("TABLE");
>>> t.style.position = "absolute";[/color]
>>
>> t.style.left = 100 + i*250 + "px";[/color]
>
> And use it here for your buffer between tables (they will overlap if
> the image is greater than 250px wide) - which is fine.
>
> [...]
>[color=green][color=darkred]
>>> // create image
>>> var i = document.createElement("IMG");
>>> i.src = "a.gif";[/color][/color][/color]
I moved the previous line to after
c.appendChild(myimg)
and now it seems to work correctly in IE.
[color=blue][color=green][color=darkred]
>>> i.style.border = "1px solid pink";[/color][/color]
>
> BUT... here you re-initialise i as an image element. I can't
> understand how IE still only loops 4 times, Safari just barfed after
> the first loop.
>
> [...][/color]
Dang I've been clumsy - it's now 'myimg'.[color=blue]
>[color=green][color=darkred]
>>> if (document.getElementsByTagName) {
>>> var docBody = document.getElementsByTagName("body")[0];
>>> } else if (document.all) {
>>> var docBody = document.all.tags("body")[0];
>>> }[/color][/color]
>
>
> I would put this before the for loop - you only need to find the body
> reference once.[/color]
Thanks, I've moved it out of the loop.
Though I've got it working now if I move the myimg.src line back to it's
original line position it also works but during testing, after I've run
the file a while, it fails. Once it fails if I move the line and test it
it works. Then if I move the line back it works for a short while again.
I guess this is why people love IE so much.
Andrew Poulos |