admin管理员组文章数量:1301478
I have javascript
function and that should be called after 3 seconds of complete page load. I know about setIntervel
but it repeat execution after certain time interval. I want it to execute once. Is it even possible?
I have javascript
function and that should be called after 3 seconds of complete page load. I know about setIntervel
but it repeat execution after certain time interval. I want it to execute once. Is it even possible?
- Possible duplicate of How to delay calling of javascript function? – Vadzim Commented Nov 1, 2017 at 1:15
3 Answers
Reset to default 11The onload event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading, After
onload
you can usesetTimeout
to delay your function execution..
var myFunc = function() {
alert('After 3 seconds of page load!');
}
window.onload = function() {
setTimeout(myFunc, 3000);
}
Use setTimeout
instead, as it is called only once after the pause:
setTimeout(myFunc, 3000);
Using setTimeout:
setTimeout(function(){myfunc()}, 3000);
with lambda..
本文标签: javascriptExecute JS function after some time of page loadStack Overflow
版权声明:本文标题:javascript - Execute JS function after some time of page load - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738515141a2091040.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论