code: function contentLoaded(callback) {
      var addEventListener = doc['addEventListener'];
      var done = false, top = true,
          add = addEventListener ? 'addEventListener' : 'attachEvent',
          rem = addEventListener ? 'removeEventListener' : 'detachEvent',
          pre = addEventListener ? '' : 'on',
  
          init = function(e) {
            if (e.type == 'readystatechange' && doc.readyState != 'complete') {
              return;
            }
            (e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
            if (!done && (done = true)) { callback.call(win, e.type || e); }
          },
  
          poll = function() {
            try {
              root.doScroll('left');
            } catch(e) {
              win.setTimeout(poll, 50);
              return;
            }
            init('poll');
          };
  
      if (doc.readyState == 'complete') {
        callback.call(win, 'lazy');
      } else {
        if (doc.createEventObject && root.doScroll) {
          try { top = !win.frameElement; } catch(e) { }
          if (top) { poll(); }
        }
        doc[add](pre + 'DOMContentLoaded', init, false);
        doc[add](pre + 'readystatechange', init, false);
        win[add](pre + 'load', init, false);
      }
    }
docs: From http://javascript.nwbox.com/ContentLoaded/contentloaded.js Author: Diego Perini (diego.perini at gmail.com) Summary: cross-browser wrapper for DOMContentLoaded Updated: 20101020 License: MIT Version: 1.2