window.onload想必大家都有使用过吧,在窗口加载时执行,如果多次使用window.onload该如何判断呢?看看下面的代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<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> |