如何在Twitter嵌入的时间表上刷新之前设置超时?
我需要更改超时时间,以更新我的网站上的twitter时间表。目前,twitter每秒钟都会执行一个ajax请求来更新时间表。但是在JS引擎慢的浏览器上(换句话说:即),会导致浏览器变慢,或者有时导致浏览器停止工作。
要解决这个问题,我需要在Twitter时间表刷新之前设置超时
我没有在API上找到任何关于我如何做到这一点的参考。
我使用下面的JS代码导入时间线:
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p='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>为了显示时间表,我使用的HTML代码如下所示:
<div class="box-twitter">
<p class="title-box"><span class="icon"></span>WHAT'S HAPPENING ON TWITTER </p>
<a class="twitter-timeline" href="https://twitter.com/search?q=from:dev include:retweets" data-widget-id="394816085830025216"><img src="preloader.gif" style="margin-left: 132px; margin-top: 20px;"/></a>
有人知道我怎么解决这个问题吗?
谢谢。
发布于 2013-11-08 19:18:19
在做了反向工程后,在widget.js文件上,由Twitter提供。我找到了一个名为“schedulePolling”的方法,代码如下:
schedulePolling: function(e) {
var t = this;
if (this.pollInterval === null) return;
e = twttr.widgets.poll || e || this.pollInterval || 1e4, e > -1 && window.setTimeout(function() {
this.isUpdating || t.update(), t.schedulePolling()
}, e)为了增加超时,我在这段代码中添加了一个固定值。
schedulePolling: function(e) {
var t = this;
if (this.pollInterval === null) return;
e = 60000 || e || this.pollInterval || 1e4, e > -1 && window.setTimeout(function() {
this.isUpdating || t.update(), t.schedulePolling()
}, e)}在我想要“60000”的时候,我已经替换了代码twttr.widgets.poll;
完成此操作后,使用我的自定义代码保存widget.js。
因此,在进行此定制之后,我修改了导入Twitter的行,将默认值//platform.twitter.com/widgets.js更改为自定义文件my-site/js/customized_widgets.js的路径。
这就是结果。
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p='https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"/my-site/js/customized_widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>发布于 2013-11-07 18:20:32
我相信设置一个Tweet limit是一种选择。
Tweet限制: To fix the size of a timeline to a preset number of Tweets, use the data-tweet-limit="5“属性 with any value between 1 and 20 Tweets. The timeline will render the specified number of Tweets from the timeline, expanding the height of the widget to display all Tweets without scrolling. ,因为该小部件大小固定,在使用此选项时不会轮询更新。
https://dev.twitter.com/docs/embedded-timelines
例如:
<a class="twitter-timeline" href="https://twitter.com/twitterapi" data-widget-id="YOUR-WIDGET-ID-HERE" data-chrome="nofooter" data-tweet-limit="3">Tweets by @twitterapi</a>
如果需要的话,您可以手动更新小部件,方法是删除它们,重新插入html,然后调用。
twttr.widgets.load()
https://stackoverflow.com/questions/19842919
复制相似问题