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
Release: 2016-05-16 16:35:55
Original
1379 people have browsed it

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> 
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template