[英]How to setup the timeout before a refresh on Twitter embedded timelines?
我需要更改超時時間來更新我網站上的推特時間線。 目前twitter API每秒都會執行ajax請求來更新時間軸。 但是在JS的引擎較慢的瀏覽器(換句話說:IE)上,導致瀏覽器變慢或者有時會導致瀏覽器停止工作。
為了解決這個問題,我希望在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>
有人知道如何解決這個問題?
謝謝。
我相信設置Tweet limit
可能是一種選擇。
推文限制: 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.
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()
在Twitter上提供的widget.js文件上進行逆向工程。 我找到了一個名為'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)}
我已經將代碼twttr.widgets.poll
替換為我想要'60000'的時間;
執行此操作后,使用我的自定義代碼保存widget.js。
因此,在此自定義之后,我修改了導入Twitter API的行,將默認值//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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.