问题描述
如何在Twitter嵌入时间轴上刷新前设置超时时间?
我需要更改超时时间以更新我网站上的Twitter时间轴。
目前,twitter API每秒都会发出ajax请求来更新时间表。
但是在浏览器中使用JS引擎缓慢的引擎(换句话说就是IE),会导致浏览器变慢,或者有时会导致浏览器停止工作。
解决这个问题我想在Twitter时间表上刷新之前设置超时时间
我没有在API上找到任何有关如何执行此操作的参考。
我使用下面的JS代码导入时间轴:
< script> !函数(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);< /脚本>
为了显示时间线,我使用了如下所示的HTML代码:
< div class =box-twitter>
< p class =title-box>< span class =icon>< / span> TWITTER正在发生什么< / p>
< a class =twitter-timelinehref =https://twitter.com/search?q=from:dev include:retweetsdata-widget-id =394816085830025216>< img src =preloader.gifstyle =margin-left:132px; margin-top:20px;/>< / a>
有人知道我该如何解决这个问题?
谢谢。
,由Twitter提供的widget.js文件。
我找到了一个名为'schedulePolling'的方法,代码如下:
pre $ 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){
pre>
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)}
我替换了我想要的代码
twttr.widgets.poll
'60000';
完成后,使用我自定义的代码保存widget.js。
在这个定制之后,我修改了导入Twitter API的行,将默认值
// platform.twitter.com/widgets.js
更改为我定制的路径filemy-site / js / customized_widgets.js
。
这是结果。
< script>!function(d,s,id){var js,fjs = d.getElementsByTagName(s)[0],p =' HTTPS';如果{JS = d.createElement(S)(d.getElementById(ID)!); js.id = ID; js.src = p + /我的网站/ JS / customized_widgets.js; fjs.parentNode .insertBefore(JS,FJS);}}(文件, 脚本, 推 - WJS);< /脚本>
How can I setup the timeout before a refresh on Twitter embedded timelines?
I need change the timeout time to update the twitter timelines on my site.Currently each second the twitter API do a ajax request to update the timelines.But on browser with slow engines of JS (in other words: IE), causes the browser becomes slow or sometimes causes the browser to stop working.
To fix this I want setup the timeout before a refresh on Twitter timelines
I didn't found any reference on API about how I can do this.
I'm using the follow JS code to import the timeline:
<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>
To show the timelines I'm using a HTML like code shown below:
<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>
Someone know how can I solve this problem?
Thanks.
解决方案After do a reverse engineering, on widget.js file, provided by Twitter.I've found a method called 'schedulePolling', with the code below:
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)
To increase the timeout I've added a fixed value on this code.
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)}
I've replaced the code
twttr.widgets.poll
for the time that I wanted '60000';After do this a save the widget.js with my customized code.
So, after this customization I've modify the line where the Twitter API was imported, changing the default value
//platform.twitter.com/widgets.js
to the path of my customized filemy-site/js/customized_widgets.js
.This is the result.
<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>
这篇关于如何在Twitter嵌入式时间表上刷新之前设置超时时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!