Home > Article > Web Front-end > Method to determine whether window.onload is used multiple times_javascript skills
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>