Skip to content

Instantly share code, notes, and snippets.

@gregberge
Created January 22, 2013 15:41
Show Gist options
  • Save gregberge/4595628 to your computer and use it in GitHub Desktop.
Save gregberge/4595628 to your computer and use it in GitHub Desktop.
JavaScript cross browser addLoadEventListener() #onload #load
function addLoadEventListener (listener) {
var done, oldonload;
if(typeof addEventListener !== "undefined") {
return addEventListener("load", listener, false);
}
if(typeof attachEvent !== "undefined") {
return attachEvent("onload", listener);
}
oldonload = onload;
if (typeof onload !== 'function') {
onload = listener;
}
else {
onload = function () {
oldonload && oldonload();
listener();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment