views:

453

answers:

7

On a site I am working on I load up a series of images which can be animated using some controls I implemented w/javascript. Everything works just fine in all browsers but IE6 which locks up and never recovers; at least not w/in the 15min I let it sit there.

The part it is choking on is a portion where I try to modified the contents of a particular div.

Before problem:

<div id='animation_image'></div>

After problem:

<div id="animation_image">  
  <div id="daily_loop_image_13" class="loop_image">
    <img name="animation" src="/path/to/image/13/20100119/world_14.gif" 
      class="hiddenElements" border="0">
    </div> 
  <div id="daily_loop_image_12" class="loop_image">
    <img name="animation" src="/path/to/image/12/20100119/world_13.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_11" class="loop_image">
    <img name="animation" src="/path/to/image/11/20100119/world_12.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_10" class="loop_image">
    <img name="animation" src="/path/to/image/10/20100119/world_11.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_9" class="loop_image">
    <img name="animation" src="/path/to/image/9/20100119/world_10.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_8" class="loop_image">
    <img name="animation" src="/path/to/image/8/20100119/world_9.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_7" class="loop_image">
    <img name="animation" src="/path/to/image/7/20100119/world_8.gif" 
      class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_6" class="loop_image">
    <img name="animation" src="/path/to/image/6/20100119/world_7.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_5" class="loop_image">
    <img name="animation" src="/path/to/image/5/20100119/world_6.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_4" class="loop_image">
    <img name="animation" src="/path/to/image/4/20100119/world_5.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_3" class="loop_image">
    <img name="animation" src="/path/to/image/3/20100119/world_4.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_2" class="loop_image">
    <img name="animation" src="/path/to/image/2/20100119/world_3.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_1" class="loop_image">
    <img name="animation" src="/path/to/image/1/20100119/world_2.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="daily_loop_image_0" class="loop_image">
    <img name="animation" src="/path/to/image/0/20100119/world_1.gif" 
        class="" border="0">
  </div> 
  <div id="weekly_loop_image_1" class="loop_image">
    <img name="animation" src="/path/to/weeklyImage/1/20100119/world_wk2max.gif" 
        class="hiddenElements" border="0">
  </div> 
  <div id="weekly_loop_image_0" class="loop_image">
    <img name="animation" src="/path/to/weeklyImage/0/20100119/world_wk1max.gif" 
        class="hiddenElements" border="0">
  </div>
</div>

I've tried:

  • storing all the elements w/in animation_image as a string and setting that to be the innerHTML
  • creating empty/placeholder divs w/in animation_image and populating them individually
  • using appendChild instead of innerHTML
  • adding another div under "animation_image" and putting all the images/divs in there using the 3 methods above this

None of it seems to work in IE6 - all methods work just fine in FF3.0+, IE7+, Chrome 2+, etc. If I exit the javascript prior to the innerHTML it works just fine but if I even try to populating a single div (within animation_image) via the method in the 2nd bullet point, it locks up and never recovers.

I'm sure I left something out but I am totally freaking out ATM. Thanks in advance.

Update: Here is a link to the javascript along w/sample XML (http://pastebin.com/m5b426a67)

A: 

Another option might be to use a sprite. Collect all of the disparate images into a single file and position the large image appropriately in the divs using CSS background properties (position, repeat, etc.) I'm not sure how large your individual files are, but this might work for you.

There are many links on the internet for how to do this, but here is one.

Upper Stage
Images are ~800x600px.
malonso
That's pretty big...
Upper Stage
Yeah, I'm not sure this would end up being the best approach given the size of my images. Good call though.
malonso
You might try an experiment - use a sprite and smaller images. If it works, you might have a better idea of the source of your problem.
Upper Stage
Mmm, I suspect IE6 might struggle a bit with throwing 800x600 images around in memory. It's not the fastest browser of all time...
Olly Hodgson
A: 

There's nothing that jumps out immediately.

First thing I'd do is try the script standalone: Literally create a blank HTML page with only this script on it. If it works, it's likely that some other bit of script is causing the problem.

If it still breaks, try simplifying the script. Try stripping back the output you're putting in animHTML, e.g try it without all the attributes. Maybe alert (or otherwise output) animHMTL to see if there's anything obvious in there that'd break IE? Perhaps a weird/badly encoded character in the XML?

Olly Hodgson
Hey Olly, thanks for the feedback. I tried isolating it as much as possible and still run into the issue. The XML seems to validate w/out any issues - webdev toolbar doesn't complain about anything at least. I also tried only updating 1 div at a time w/an image tag (total of 52chars) and it still had the same problem. I gotta be screwing something up but cannot figure it out for the life of me.
malonso
Just before $('#animation_image').html(animHTML); add in something like animHTML = "<p>Testing 123</p>"; and see if it still happens. Or try it without the img tags.
Olly Hodgson
That works just fine. I also tried hard-coding a div-wrapped image tag in there and it worked fine. This blows my mind b/c I've swapped out div and span elements that contained 1000+ characters and it works fine in IE6. Blah.
malonso
A: 

I have a similar problem earlier and fixed it by setting a timeout on the innerHTML method. I am not pretty sure whether it applies here or not, but I would say just give it a try.

Teja Kantamneni
Hi Teja, I tried that and it didn't seem to work. Could you post a snippet of what you did so that I can confirm I am doing what I should be. Thanks.
malonso
A: 

This problem is one I've seen a few times. In IE, there seems (to me anyway) to be a bug when setting the innerHTML property with something that contains external resources (an image, a script, etc).

You are adding a few img tags. Each one could cause this problem. Here is what I recommend:

Instead of building this html and setting the innerHTML property

var html = '<div id="daily_loop_image_4" class="loop_image">
    <img name="animation" src="/path/to/image/4/20100119/world_5.gif"
         class="hiddenElements" border="0">
</div>';
outerDiv.innerHTML = html;

Run this script to add the html:

var div = document.createElement('div');
div.id = 'daily_loop_image_4';
div.className = 'loop_image';

var img = document.createElement('img');
img.name = 'animation';
img.src = '/path/to/image/4/20100119/world_5.gif';
img.className = 'hiddenElements';
img.border = 0; //Shouldn't this be done in css?

div.appendChild(img);
outerDiv.appendChild(div);
Gabriel McAdams
Thanks Gabriel, I'm going to assume that something goofy happened to that img.src specification and that it should be something like: img.src ="/path/to/image/4/20100119/world_5.gif"; Right?
malonso
I actually vaguely recall trying something like this before but I went ahead w/it anyway and it works fine in all browsers I tested (FF3+, IE7+, Chrome 3+, Opera 9.6+) but still hangs in IE6. This whole thing is getting REALLY frustrating. If I comment out the outerDiv append statement the thing finishes instantly - I realize the loading of images takes a while but it is only loading <400-500K worth of images.
malonso
Ok there's obviously some sort of memory goofiness going on here. If I hard-code the image path for the entire series of (14) images to point to the exact same 0.79KB image, it works. Same 19.24KB image, it works. Same 34.75KB image, it FAILS. If I even go all the way back to using FF1.5.0.6 everything loads up instantly. Test PC is P-4 2.8GHz w/1Gb RAM. Just to piss me off even more, after sitting there for 10+ minutes I try to kill it and after confirming that I want to end the application it will occasionally show the page w/all the images loaded and then close it a half-second later.
malonso
Yeah. I fixed the img.src typo in my answer. Thanks for catching that.
Gabriel McAdams
A: 

I may have missed this as I only glanced over the code but any DOM manipulation has to be done after DOM Ready, especially in IE6. Have you tried this?

$(document).ready(function(){
 $('#animation_image').html(animHTML);
});

If you have tried this then I'll look into this further.

MJJames
Sorry, I should have mentioned that I was doing that in the beginning - the function that handles the innerHTML is called at the end of a $(document).ready section. Good suggestion though.
malonso
+1  A: 

Not quite sure how I missed this in my days and days of googling but it looks like the issue is related to the AlphaImageLoader "fix" for dealing w/transparent PNGs. The article I found gets into more detail about the underlying issue:

http://blogs.cozi.com/tech/2008/03/transparent-pngs-can-deadlock-ie6.html

When I removed the entry in png_fix.css the page - in its original form - loaded flawlessly in IE6. Now I just need to go and try to convert all the (transparent) pngs to gifs which might not be a feasible solution either.

I really appreciate everyone's help and I apologize for any wild goose chases I sent people on. Thank you all VERY VERY much.

malonso
A: 

If nothing else works, you can use a try...catch statement and display a friendly error message if the try is caught.

Arlen Beiler
Hey Arlen, thanks for the suggestion. Unfortunately, I am not sure that would work in this situation since the browser is completely locking up and unresponsive.
malonso