Browse Source

Update DOMContentLoaded event handler in app.js

Konstantin Tarkus 9 years ago
parent
commit
bef2a3a19f
1 changed files with 4 additions and 5 deletions
  1. 4 5
      app.js

+ 4 - 5
app.js

@@ -30,12 +30,11 @@ function run() {
 }
 
 if (canUseDOM) {
-// Run the application when both DOM is ready
-// and page content is loaded
-  if (window.addEventListener) {
-    window.addEventListener('DOMContentLoaded', run);
+  // Run the application when both DOM is ready and page content is loaded
+  if (['complete', 'loaded', 'interactive'].includes(document.readyState) && document.body) {
+    run();
   } else {
-    window.attachEvent('onload', run);
+    document.addEventListener('DOMContentLoaded', run, false);
   }
 }