Posted By

inamorix on 06/26/07


Tagged

js


Versions (?)

onDOMReadyLite


 / Published in: JavaScript
 

  1. function onDOMReadyLite (fn) {
  2. var d = document;
  3. if (/safari/i.test(navigator.userAgent)) {
  4. var readystate = function () {
  5. if (/loaded|complete/.test(d.readyState)) {
  6. clearInterval(timer);
  7. fn();
  8. }
  9. }
  10. var timer = setInterval(readystate, 50);
  11. }
  12. else if (d.all && !window.opera) {
  13. var src = (location.protocol == 'https:') ? '://0' : 'javascript:void(0)';
  14. d.write('<script src="' + src + '" defer="defer" id="__tmp__"></script>');
  15. d.getElementById('__tmp__').onreadystatechange = function(){
  16. if (this.readyState == 'complete') {
  17. this.parentNode.removeChild(this);
  18. fn();
  19. }
  20. };
  21. }
  22. else {
  23. d.addEventListener('DOMContentLoaded', fn, false);
  24. }
  25. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: senixon on July 17, 2008

seems to break in FF3.0 (maybe otheres) on

else { d.addEventListener('DOMContentLoaded', fn, false); }

You need to login to post a comment.