check if DOM content is loaded. 2. Added script source to index.html. 3. Used script in index.js.pull/92/head
parent
f0f07ee543
commit
890a377ce7
@ -0,0 +1,25 @@
|
|||||||
|
var domIsReady = (function (domIsReady) {
|
||||||
|
var isBrowserIeOrNot = function () {
|
||||||
|
return (!document.attachEvent || typeof document.attachEvent === "undefined" ? 'not-ie' : 'ie');
|
||||||
|
}
|
||||||
|
|
||||||
|
domIsReady = function (callback) {
|
||||||
|
if (callback && typeof callback === 'function') {
|
||||||
|
if (isBrowserIeOrNot() !== 'ie') {
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
return callback();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
document.attachEvent("onreadystatechange", function () {
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('The callback is not a function!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return domIsReady;
|
||||||
|
})(domIsReady || {});
|
@ -0,0 +1,6 @@
|
|||||||
|
(function (document, window, domIsReady, undefined) {
|
||||||
|
domIsReady(function () {
|
||||||
|
console.log('My DOM is ready peeps!');
|
||||||
|
|
||||||
|
});
|
||||||
|
})(document, window, domIsReady);
|
Loading…
Reference in new issue