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>