简体   繁体   English

innerHTML导致IE6(永久地)锁定

[英]innerHTML causes IE6 to (permanantly) lock up

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. 在我正在处理的网站上,我加载了一系列图像,这些图像可以使用我用javascript实现的一些控件进行动画处理。 Everything works just fine in all browsers but IE6 which locks up and never recovers; 在所有浏览器中一切正常,但IE6锁定并且永远不会恢复; at least not w/in the 15min I let it sit there. 至少不是在15分钟内,我让它坐在那里。

The part it is choking on is a portion where I try to modified the contents of a particular div. 它窒息的部分是我试图修改特定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 将animation_image中的所有元素作为字符串存储并将其设置为innerHTML
  • creating empty/placeholder divs w/in animation_image and populating them individually 在animation_image中创建空/占位符div并单独填充它们
  • using appendChild instead of innerHTML 使用appendChild而不是innerHTML
  • adding another div under "animation_image" and putting all the images/divs in there using the 3 methods above this 在“animation_image”下添加另一个div,并使用上面的3个方法将所有图像/ div放在那里

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. 似乎没有一个在IE6中工作 - 所有方法在FF3.0 +,IE7 +,Chrome 2+等都可以正常工作。如果我在innerHTML之前退出javascript它工作得很好但是如果我甚至尝试填充单个div(在animation_image中)通过第二个项目符号点中的方法,它会锁定并且永远不会恢复。

I'm sure I left something out but I am totally freaking out ATM. 我确定我遗漏了一些东西,但我完全吓坏了ATM。 Thanks in advance. 提前致谢。

Update: Here is a link to the javascript along w/sample XML ( http://pastebin.com/m5b426a67 ) 更新:以下是带有示例XML的javascript链接( http://pastebin.com/m5b426a67

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. 我不太确定在谷歌的日子和日子里我是如何错过这一点的,但看起来这个问题与处理w /透明PNG的AlphaImageLoader“修复”有关。 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 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. 当我删除png_fix.css中的条目时,页面 - 以其原始形式 - 在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. 现在我只需要尝试将所有(透明)png转换为gif,这可能也不是一个可行的解决方案。

I really appreciate everyone's help and I apologize for any wild goose chases I sent people on. 我真的很感谢大家的帮助,我为任何人们发送的疯狂追逐道歉。 Thank you all VERY VERY much. 非常感谢你们。

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. 将所有不同的图像收集到一个文件中,并使用CSS背景属性(位置,重复等)将大图像正确放置在div中。我不确定您的单个文件有多大,但这可能对您有用。

There are many links on the internet for how to do this, but here is one . 互联网上有很多关于如何做到这一点的链接,但这里有一个

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. 我要做的第一件事是独立尝试脚本:字面上创建一个空白的HTML页面,上面只有这个脚本。 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 , eg try it without all the attributes. 尝试剥离你在animHTML输出的输出,例如尝试没有所有属性。 Maybe alert (or otherwise output) animHMTL to see if there's anything obvious in there that'd break IE? 也许alert (或以其他方式输出) animHMTL以查看是否有任何明显的东西会破坏IE? Perhaps a weird/badly encoded character in the XML? XML中可能是一个奇怪/编码不好的字符?

I had a similar problem earlier and fixed it by setting a timeout on the innerHTML method. 我之前遇到过类似的问题,并通过在innerHTML方法上设置超时来修复它。
I am not sure whether it applies here or not, but I would say just give it a try. 我不确定它是否适用于此,但我想说试试看。

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). 在IE中,当使用包含外部资源(图像,脚本等)的东西设置innerHTML属性时,似乎(无论如何)是一个错误。

You are adding a few img tags. 您正在添加一些img标签。 Each one could cause this problem. 每一个都可能导致这个问题。 Here is what I recommend: 这是我的建议:

Instead of building this html and setting the innerHTML property 而不是构建此html并设置innerHTML属性

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: 运行此脚本以添加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);

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. 我可能错过了这个,因为我只浏览了代码,但任何DOM操作都必须在DOM Ready之后完成,特别是在IE6中。 Have you tried this? 你试过这个吗?

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

If you have tried this then I'll look into this further. 如果您已经尝试过这个,那么我将进一步研究这个问题。

如果没有其他工作,您可以使用try ... catch语句并在捕获尝试时显示友好的错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM