Method to determine whether window.onload is used multiple times
- 2020-03-30 03:57:13
- OfStack
Window.onload, which you've probably used before, is executed when the window is loaded. How do you determine if you use window.onload multiple times? Take a look at the code below
<script>
function onloadCallback(){
//Todo
}
if (window.onload) {
var onload_random = 'onload'+Math.random();
window[onload_random] = window.onload;
window.onload = function (){
window[onload_random]();
onloadCallback();
};
}
else {
window.onload = function (){
onloadCallback();
};
}
</script>