简体   繁体   English

如何每隔几秒执行一次外部 JavaScript?

[英]How do I execute an external JavaScript every few seconds?

I like to load an external JavaScript once every 10 seconds or so.我喜欢每 10 秒左右加载一次外部 JavaScript。 Or whenever the body of the page is clicked(if so, I need to run the script only if few seconds are passed).或者每当单击页面正文时(如果是这样,我只需要在经过几秒钟后运行脚本)。 Even if anyone points me to the documentation., it will be more than sufficient.即使有人指出我的文档,也绰绰有余。

setInterval(function(){ alert("Hello"); }, 10000); //will execute the alert every 10 seconds.
Please find an example here.请在此处找到示例。
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_setinterval https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_setinterval

You can try bellow code snippet :您可以尝试以下代码片段:

index.html索引.html

<html>
<head>
<body onClick="refreshPage()">

this page will refresh in every 10 seconds
</body>
</html>

<script src="script.js"></script>

script.js脚本.js

function refreshPage(){
    window.location.reload();
}

setTimeout(function(){
    window.location.reload();
 }, 10000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每隔几秒执行一次外部 javascript - Executing an external javascript once every few seconds 每隔几秒刷新一次外部网页 - Refresh an external webpage every few seconds 如何每60秒调用一次JavaScript函数? - How do I call a JavaScript function every 60 seconds? 如何在JavaScript中每隔几秒钟调用一次函数? - How do I call a function every whatever seconds in Javascript? 如何使用 javascript 每 X 秒刷新一次浏览器? - How do I refresh the browser every X seconds with javascript? 您如何每隔几个车轮滴答声或每隔几秒调用一次车轮 function? - How do you call a wheel function every few wheel ticks or every few seconds? javascript:我想每 X 秒执行 1 个命令 - javascript : I want execute 1 command every X seconds 如何在几秒钟后更改图像期间添加 FadeIn/FadeOut javascript 效果 - How do I add FadeIn/FadeOut javascript effect during images change after a few seconds 如何从外部VBScript执行网页中的Javascript函数 - How do I Execute Javascript Function in webpage from external VBScript 如果用户空闲,我如何编写一个每隔几秒钟在 html 网页上的选项卡之间移动的 javascript 函数 - How can I write a javascript function that moves between my tabs on a html webpage every few seconds if the user is idle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM