Last active
November 23, 2017 07:43
-
-
Save googlicius/3951ac84aeabc21d53de28999032a159 to your computer and use it in GitHub Desktop.
Method to add one or more function handler on an element's onload event...
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
/** | |
* Method to add one or more function handler on an element's onload event | |
* This is because onload cannot carry out many separate functions. | |
* | |
* @param {any} element DOM element | |
* @param {any} handler function | |
*/ | |
const addOnloadHandler = (element, handler) => { | |
if (typeof element.onload === 'function') { | |
const pre_func = element.onload; | |
element.onload = () => { | |
pre_func(); | |
handler(); | |
} | |
} | |
else { | |
element.onload = handler; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment