twitter 小部件仅在 webapp ajax 页面中首次加载? [英] twitter widget only load first time in webapp ajax page?
问题描述
我正在尝试在我的 ajax 加载页面中加载 twitter 小部件 api.
我尝试以几种不同的方式加载脚本,每次运行时都会收到警报,但脚本本身却没有.
所以我第一次加载页面时,脚本正在运行,但是如果我返回菜单并返回此页面,那么它不会加载它?
这是 ajax 加载的页面.
<div id="twitterwid"><a class="twitter-timeline" width="320" height="500" href="https://twitter.com/my account" data-widget-id="my widget id number">加载推文@我</a><脚本>alert("警报有效");!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</脚本>任何意见表示赞赏,谢谢.
解决方案 您所要做的就是:调用页面上的小部件标签的重新渲染:
twttr.widgets.load()
注意:内联脚本不会在 AJAX 加载时执行.请参阅:此 SO Q&A 以获得解决方案.
Im trying to load the twitter widget api in my ajax loaded page.
I have tryed to load the script in a couple of different ways and Im getting the alert to run each time but not the script itself.
So the first time I load the page, then the script is working, but if I go back to the menu and back to this page, then it doesnt load it?
This is the ajax loaded page.
<div id="twitterwid">
<a class="twitter-timeline" width="320" height="500" href="https://twitter.com/my account" data-widget-id="my widget id number">Loading tweets by @me</a>
<script>
alert("alert is working");
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<div>
Any input appreciated, thanks.
解决方案 All you have to do is: invoke a re-render of the widget tags on the page by calling:
twttr.widgets.load()
Similar question on Twitter Dev Channel
Note: inline script is not executed upon AJAX Load.
See: this SO Q&A for the solution to that.
这篇关于twitter 小部件仅在 webapp ajax 页面中首次加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文