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>