社交媒体弹出窗口
我的网站的社交媒体插件有问题,问题出在 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>');
有解决办法吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于每次打开弹出窗口时都会插入插件代码,因此请务必调用
jQuery("#MyDiv").dialog("destroy");
。有关详细信息,请参阅 http://jqueryui.com/demos/dialog/。此外,您可能需要根据 parsetags 设置为
explicit
“nofollow">https://developers.google.com/+/plugins/+1button/ 并在 jQuery 对话框的 open 事件中调用gapi.plusone.render()
。Since you're inserting the plugin code each time the popup opens, be sure to call
jQuery("#MyDiv").dialog("destroy");
. See http://jqueryui.com/demos/dialog/ for more information.Also you may need to set the
parsetags
toexplicit
per https://developers.google.com/+/plugins/+1button/ and callgapi.plusone.render()
in the open event of the jQuery dialog.问题出在异步加载的 javascript 代码中。它可能会在弹出窗口之外创建一个脚本标签。在第二次调用时,它会检查该标记是否已存在并且不执行任何操作。查找
if(!d.getElementById(id))
部分。然而,在您的情况下,异步加载器无论如何都没有意义,因为在用户打开弹出窗口时页面已经完全加载。
因此您可以直接包含外部脚本。当再次显示弹出窗口时,完整的内容将被清除,包括那些脚本标签。
打开弹出窗口和完全加载按钮之间有一点延迟,尤其是在互联网连接速度较慢的情况下。为了防止更快的按钮跳来跳去,我将它们放入 div.elements 中,并在 CSS 中定义了 24px 的固定高度。
The problem is in the javascript code for the asynchronous loading. It may create a script tag outside the popup window. On the second invocation, it checks that this tag already exists and does nothing. Look for the
if(!d.getElementById(id))
part.In your case, however, the asynchronous loader does not make sense anyway, as the page is already completely loaded at the time the user opens the popup.
Therefore you can include the external scripts directly. When the popup is shown again, the complete content will be cleared, including those script tags.
There is a little delay between opening the popup windows and the buttons being completely loaded, especially on slow Internet connections. In order to prevent the faster buttons from jumping around, I put them into div.elements for with I defined fixed height of 24px in CSS.