From 1904d6bf50f64c875ae2244d0809e8498f15e8bb Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Mon, 9 Jun 2014 23:04:18 -0700 Subject: [PATCH] More reliable document ready detection. --- static/cosmopolite.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 3f1bb99..263da27 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -134,7 +134,7 @@ var Cosmopolite = function( if (document.readyState == 'complete') { this.init_(); } else { - document.addEventListener('DOMContentLoaded', this.init_.bind(this)); + document.addEventListener('readystatechange', this.init_.bind(this)); } }; @@ -508,6 +508,10 @@ Cosmopolite.prototype.trackEvent = function(var_args) { * @private */ Cosmopolite.prototype.init_ = function() { + if (document.readyState != 'complete') { + return; + } + /** * @type {Promise} * @private