开发者

fireContentLoadedEvent is being called prematurely in ie

I've got an issue that's only just started happening under ie8. my code has been working for some time, and still works fine in firefox but for some reason prototype just stopped calling my event listeners for dom:loaded.

i attach them via document.observe("dom:loaded", callback);

after some de开发者_如何学Cbugging (i hate ie's debugger!!!) i've come to the conclusion that prototype's fireContentLoadedEvent (ln 4102) is being called well before the dom is loaded (almost immediately after the document.write("<script...")).

fireContentLoadedEvent is being called from the handler for when !document.addEventListener ie (see prototype.js line 4125)

  ...
  if (document.addEventListener) {
  ...
  } else {
    document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
    $("__onDOMContentLoaded").onreadystatechange = function() {
      if (this.readyState == "complete") {
        this.onreadystatechange = null;
        fireContentLoadedEvent();
      }
    };
  }
  ...

does anyone who understands this mechanism have any ideas regarding why it might trigger prematurely?


i figured it out........... !!

in IE, if you change the innerHTML of any element during page load, all "deferred" scripts are loaded prematurely...

one of my inline javascript procedures was changing the innerHTML of an element during page load and delaying this script resolved the issue for me.

so the thing i need to remember is:

never change innerHTML until after page load!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜