Skip to content

Instantly share code, notes, and snippets.

@parkerproject
Created September 20, 2016 20:47
Show Gist options
  • Select an option

  • Save parkerproject/967e400aaeb0404ab439ce0bd498c428 to your computer and use it in GitHub Desktop.

Select an option

Save parkerproject/967e400aaeb0404ab439ce0bd498c428 to your computer and use it in GitHub Desktop.
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function () {
oldonload();
func();
}
}
}
function addEvent(elm, evType, fn, useCapture) {
if (elm.addEventListener) {
elm.addEventListener(evType, fn, useCapture);
return true;
} else if (elm.attachEvent) {
var r = elm.attachEvent('on' + evType, fn);
return r;
} else {
elm['on' + evType] = fn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment