社交媒体弹出窗口

发布于 2025-01-02 19:50:19 字数 2011 浏览 3 评论 0 原文

我的网站的社交媒体插件有问题,问题出在 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+'&amp;send=false&amp;layout=button_count&amp;width=125&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;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>');

有解决办法吗?

I have a problem with the social media plugins for my website, The problem is with Twitter and Facebook. Google+ works perfectly.

I'm trying to get the plugins to work with my popup script in jQuery. When they click on a link the popup is added at the end of the body tags. In the function I put the JS code of Facebook, Twitter and Google+, and let the div's place on the right position. Not the problem is When I click on the popup for the first time ( after reload page ) all plugins are working fine. when I close the popup and reopen it. Only Google+ ( or Facebook with the iFrame ) is showing...

everytime when I open the popup this part of the social media plugins I call!

                // 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>');

Is there a fix for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挖个坑埋了你 2025-01-09 19:50:19

由于每次打开弹出窗口时都会插入插件代码,因此请务必调用 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 to explicit per https://developers.google.com/+/plugins/+1button/ and call gapi.plusone.render() in the open event of the jQuery dialog.

み青杉依旧 2025-01-09 19:50:19

问题出在异步加载的 javascript 代码中。它可能会在弹出窗口之外创建一个脚本标签。在第二次调用时,它会检查该标记是否已存在并且不执行任何操作。查找 if(!d.getElementById(id)) 部分。

然而,在您的情况下,异步加载器无论如何都没有意义,因为在用户打开弹出窗口时页面已经完全加载。

因此您可以直接包含外部脚本。当再次显示弹出窗口时,完整的内容将被清除,包括那些脚本标签。

var socialLink = e.attr("data-link");
var message = e.attr("data-title");
var hashtag = e.attr("data-hashtag");

var html = ''
    + '<div class="socialbutton"><iframe src="https://www.facebook.com/plugins/like.php?href='+socialLink+'&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">Loading Facebook</iframe></div>'
    + '<div class="socialbutton"><div class="g-plusone" data-size="medium" data-href="'+socialLink+'">Loading Google+</div></div>'
    + '<div class="socialbutton"><a href="https://twitter.com/share" class="twitter-share-button" data-url="' + socialLink + '" data-text="' + message + '" data-hashtags="' + hashtag + '">Loading Twitter</a></div>'

    + '<div><a href="https://stendhalgame.org/wiki/Two_clicks_for_more_privacy" target="_blank">Two clicks for more privacy.</a></div>'

    + '<script async type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>'
    + '<script async type="text/javascript" src="https://platform.twitter.com/widgets.js" id="twitter-wjs"></script>';

$('#popupContent').html(html);

打开弹出窗口和完全加载按钮之间有一点延迟,尤其是在互联网连接速度较慢的情况下。为了防止更快的按钮跳来跳去,我将它们放入 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.

var socialLink = e.attr("data-link");
var message = e.attr("data-title");
var hashtag = e.attr("data-hashtag");

var html = ''
    + '<div class="socialbutton"><iframe src="https://www.facebook.com/plugins/like.php?href='+socialLink+'&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">Loading Facebook</iframe></div>'
    + '<div class="socialbutton"><div class="g-plusone" data-size="medium" data-href="'+socialLink+'">Loading Google+</div></div>'
    + '<div class="socialbutton"><a href="https://twitter.com/share" class="twitter-share-button" data-url="' + socialLink + '" data-text="' + message + '" data-hashtags="' + hashtag + '">Loading Twitter</a></div>'

    + '<div><a href="https://stendhalgame.org/wiki/Two_clicks_for_more_privacy" target="_blank">Two clicks for more privacy.</a></div>'

    + '<script async type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>'
    + '<script async type="text/javascript" src="https://platform.twitter.com/widgets.js" id="twitter-wjs"></script>';

$('#popupContent').html(html);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文