问题
I am trying to delay the onLoad event that gets fired. Is there a way to delay this event strictly using javascript on the client side ?
回答1:
If you put a script
tag at the end of the body
like:
<body>
...
<script>
setTimeout(function(){
//deferred onload
}, 2000);
</script>
</body>
The function will be executed after 2 sec in this case
As said in my comment below: you shouldn't rely on a delay. But use a callback on a certain event. If impossible, may be a better bad solution, is to use setInterval with a function that check every X msec if the thing you are waiting for is present, and fire.
回答2:
There's no reason to delay the onload event. Maybe you want to use window.load instead?
$(window).load(function(){
//your code here
});
来源:https://stackoverflow.com/questions/7800048/how-to-delay-the-onload-event-which-gets-fired-on-the-browser