Skip to content

Instantly share code, notes, and snippets.

@abdullahoguk
Created February 25, 2021 07:17
Show Gist options
  • Save abdullahoguk/2289671f9c73c23e7693d3ac9a3db4fe to your computer and use it in GitHub Desktop.
Save abdullahoguk/2289671f9c73c23e7693d3ac9a3db4fe to your computer and use it in GitHub Desktop.
Append to "onload" function in JS
//source: https://ehikioya.com/working-with-javascript-onload-functions/
//Add function to onload without overriding previously defined onloads
AddOnLoadEvent(yourFunction);
function AddOnLoadEvent(functionX) {
var oldonloadevent = window.onload;
if (typeof window.onload != 'function') {
window.onload = functionX;
}
else {
window.onload = function () {
if (oldonloadevent) {
oldonloadevent();
}
functionX();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment