Use addEventListener to schedule BN initialisation only if document is still loading

This commit is contained in:
Michal Kleiner 2017-11-20 18:49:45 +13:00
parent 63f16e4054
commit 87b299b495
1 changed files with 4 additions and 4 deletions

View File

@ -32,13 +32,13 @@ function initialiseBetterNavigator() {
}
}
if (document.addEventListener) {
if (document.addEventListener && document.readyState === 'loading') {
document.addEventListener("DOMContentLoaded", function () {
//wait til DOM is ready
// wait til DOM finishes loading
initialiseBetterNavigator();
});
} else {
//This is the case for IE8 and below
//initialise straight away - fine if script is loaded after BN dom element
// This is the case for IE8 and below OR already loaded document (e.g. when using async)
// initialise straight away - fine if script is loaded after BN dom element
initialiseBetterNavigator();
}