views:

11

answers:

1

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 debugging (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?

A: 

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!

pstanton