我的网站的社交媒体插件有问题,问题出在 Twitter 和 Facebook 上。 Google+ 运行完美。
我正在尝试让插件与我的 jQuery 弹出脚本一起使用。当他们单击链接时,弹出窗口会添加到正文标签的末尾。在函数中我放入了Facebook、Twitter和Google+的JS代码,并将div放在正确的位置。问题不是当我第一次单击弹出窗口时(重新加载页面后),所有插件都工作正常。当我关闭弹出窗口并重新打开它时。仅显示 Google+(或带有 iFrame 的 Facebook)...
每次当我打开弹出窗口时,我都会调用这部分社交媒体插件!
// Google Code
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
// Twitter Code
!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");
if(options.socialLink != false){
var FBsocialLink = 'href='+options.socialLink;
var socialLink = 'data-href="'+options.socialLink+'"';
}
//show FB
$('.popup_container').append('<iframe src="//www.facebook.com/plugins/like.php?'+FBsocialLink+'&send=false&layout=button_count&width=125&show_faces=false&action=like&colorscheme=light&font&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:125px; height:21px;" allowTransparency="true"></iframe>');
//show Google+
$('.popup_container').append('<div class="g-plusone" data-size="medium" '+socialLink+'></div>');
//show Twitter
$('.popup_container').append('<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.rednasdesign.nl">Tweet</a>');
有解决办法吗?
最佳答案
由于您每次打开弹出窗口时都插入插件代码,因此请务必调用 jQuery("#MyDiv").dialog("destroy");
。请参阅http://jqueryui.com/demos/dialog/了解更多信息。
此外,您可能需要根据 https://developers.google.com/+/plugins/+1button/ 将 parsetags
设置为 explicit
并在 jQuery 对话框的 open 事件中调用 gapi.plusone.render()。
关于javascript - 社交媒体弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9158427/