Created
February 25, 2021 07:17
-
-
Save abdullahoguk/2289671f9c73c23e7693d3ac9a3db4fe to your computer and use it in GitHub Desktop.
Append to "onload" function in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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