window.onload想必大家都有使用過吧,在窗口加載時執行,如果多次使用window.onload該如何判斷呢?看看下面的代碼
<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>