I’m trying to find an explanation on the following question, I looked around and still haven’t found a single teaser: what is the difference between the Simon Willison code for a function AddLoadEventand a function loadfrom jQuery?
Here are the links:
Case No. 1 (jQuery.load function)
function replaceMissingImage(){
}
$(window).load(function () {
replaceMissingImage();
});
or case number 2 (AddEventLoad - JS)
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function replaceMissingImage(){
}
addLoadEvent(replaceMissingImage);
Q: Will these two pieces of code do the same?
$(window).load(function()) vs AddLoadEvent
source
share