如何在一定的时间间隔后执行脚本
how to execute script after certain interval of time
我使用twitter小部件在一个简单的网页上显示我的时间线。但我真正想实现的是,每当我从推特上发推特时,我都想在我创建的网页上看到它,而不会被刷新。所以我想做的是每隔3秒左右调用一次脚本。请让我知道怎么做。
这是我所做的html页面的代码。
<html>
<head>
<title>Twitter Feed Test</title>
</head>
<body>
<p>Testing how to get the the twitter feeds to webpage</p>
<a class="twitter-timeline" href="https://twitter.com/happyman_mayur" data-widget-id="509282432604844032">Tweets by @happyman_mayur</a>
<script>
!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
if(!d.getElementById(id))
{
js=d.createElement(s);
js.id=id;js.src=p+"://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);}
}(document,"script","twitter-wjs");
</script>
</body>
</html>
可能有一种更好的、特定于Twitter的方法,但在Javascript中最简单的方法是使用setInterval
函数。
setInterval(function () {
// Your code here
}, 3000)
更多信息
带有setInterval或setTimeout(递归);
您应该访问http://www.w3schools.com/jsref/met_win_setinterval.asp
但是要小心在卸载时清除Interval o clearTimeout
相关文章:
- 如果返回的数据是javascript,$.ajax会自动执行脚本吗
- 如果条件匹配,则停止执行脚本
- 加载服务器端渲染的React组件后执行脚本
- 量角器使用ElementArrayFinder执行脚本怪异
- 在selenium python中执行脚本
- 仅当脚本在视口中时执行脚本
- Chrome扩展:加载窗口后执行脚本
- FireFox扩展对TinyMCE编辑器执行脚本注入
- HTML表单-按'时执行脚本;输入',无需提交
- 当超出范围时,延迟执行脚本Jquery(或SetTimeOut)BUT
- 在执行脚本之前,请查看对象是否未定义
- 如何在整个网页加载后执行脚本
- 多次执行脚本的 jQuery
- 从另一个文件执行脚本
- 从单独的.php文件中执行<脚本>
- 如何防止执行脚本但在 DOM 中显示它
- 在 Mac 上的 Firebug 中继续执行脚本的快捷方式是什么?
- 文档.写入脚本内部不执行脚本
- 在页面加载之前在 ajax 请求的页面上执行脚本
- 如何对包含在父 html 中的子 html 文件执行脚本