问题描述
我正在尝试在我的 ajax 加载页面中加载 twitter 小部件 api.
我尝试以几种不同的方式加载脚本,但每次都收到运行警报,但不是脚本本身.
所以当我第一次加载页面时,脚本正在运行,但是如果我返回菜单并返回此页面,则它不会加载它?
这是ajax加载的页面.
<a class="twitter-timeline" width="320" height="500" href="https://twitter.com/my account" data-widget-id="my widget id number">加载推文来自@me</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");<div>感谢任何输入,谢谢.
解决方案 您所要做的就是:通过调用:
来调用页面上小部件标签的重新渲染: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 页面中第一次加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-27 22:07