- 31.3k
- 22
- 110
- 134
Really, if you care about IE9+Internet Explorer 9+ only, this code would be enough to replace jQuery.ready:
document.addEventListener("DOMContentLoaded", callback);
to replace jQuery.ready
If you worry about IE6Internet Explorer 6 and some really strange and rare browsers, this will work:
domReady: function (callback) {
// Mozilla, Opera and WebkitWebKit
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", callback, false);
// If IEInternet Explorer, the event model is used
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", function() {
if (document.readyState === "complete" ) {
callback();
}
});
// A fallback to window.onload, that will always work
} else {
var oldOnload = window.onload;
window.onload = function () {
oldOnload && oldOnload();
callback();
}
}
},
Really, if you care about IE9+ only, this code would be enough
document.addEventListener("DOMContentLoaded", callback);
to replace jQuery.ready
If you worry about IE6 and some really strange and rare browsers, this will work
domReady: function (callback) {
// Mozilla, Opera and Webkit
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", callback, false);
// If IE event model is used
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", function() {
if (document.readyState === "complete" ) {
callback();
}
});
// A fallback to window.onload, that will always work
} else {
var oldOnload = window.onload;
window.onload = function () {
oldOnload && oldOnload();
callback();
}
}
},
Really, if you care about Internet Explorer 9+ only, this code would be enough to replace jQuery.ready:
document.addEventListener("DOMContentLoaded", callback);
If you worry about Internet Explorer 6 and some really strange and rare browsers, this will work:
domReady: function (callback) {
// Mozilla, Opera and WebKit
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", callback, false);
// If Internet Explorer, the event model is used
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", function() {
if (document.readyState === "complete" ) {
callback();
}
});
// A fallback to window.onload, that will always work
} else {
var oldOnload = window.onload;
window.onload = function () {
oldOnload && oldOnload();
callback();
}
}
},
Really, if you care about IE9+ only, this code would be enough
document.addEventListener("DOMContentLoaded", callback);
to replace jQuery.ready
If you worry about IE6 and some really strange and rare browsers, this will work
domReady: function (callback) {
// Mozilla, Opera and Webkit
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", callback, false);
// If IE event model is used
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", function() {
if (document.readyState === "complete" ) {
callback();
}
});
// A fallback to window.onload, that will always work
} else {
var oldOnload = window.onload;
window.onload = function () {
oldOnload && oldOnload();
callback();
}
}
},