Home >Web Front-end >JS Tutorial >Method to determine whether window.onload is used multiple times_javascript skills

Method to determine whether window.onload is used multiple times_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:35:551376browse

I believe everyone has used window.onload. It is executed when the window is loading. How to judge if window.onload is used 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> 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn