简体   繁体   English

尝试自定义 Facebook 共享按钮时出错

[英]error while trying to customize a facebook share button

I wanted to customize a facebook share button, then I tried this:我想自定义一个 facebook 分享按钮,然后我尝试了这个:

<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/es_ES/sdk.js#xfbml=1&version=v6.0"></script>


<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count" data-size="small"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>

But this generate a button that I can not customize, I already have a facebook icon with css effects.但这会生成一个我无法自定义的按钮,我已经有一个带有 css 效果的 Facebook 图标。 Then I try this with my icon:然后我用我的图标试试这个:

<div id="fb-share-button">

    <a href="#" target="_blank" class="Facebook">
        <div class="inside">
            <i class="fa-facebook" style="color:#848484;font-size:16px;width:44px;height:44px;-webkit-border-radius: 50% 50% 50% 50%;-moz-border-radius: 50% 50% 50% 50%;border-radius: 50% 50% 50% 50%;line-height:44px;border-width:1px; border-style:solid;border-color:#848484;text-align:center;"></i>
            <div class="desc">Facebook</div>
        </div>
    </a>
</div>

<script>

var fbButton = document.getElementById('fb-share-button');
var url = window.location.href;

fbButton.addEventListener('click', function() {
    window.open('https://www.facebook.com/sharer/sharer.php?u=' + url,
        'facebook-share-dialog',
        'width=800,height=600'
    );
    return false;
});

</script>

This works, but the problem is that it generates a warning on my browser, about popups:这有效,但问题是它会在我的浏览器上生成一个关于弹出窗口的警告:

在此处输入图片说明

What can I do to avoid that warning?我该怎么做才能避免该警告? thank you.谢谢你。

You are not supposed to change the appearance of Social Plugins by CSS, but you have 2 other options:您不应该通过 CSS 更改社交插件的外观,但您还有其他 2 个选项:

The answer is to have an app registered on facebook: https://developers.facebook.com/apps/ Create your app to get an app id.答案是在 facebook 上注册一个应用程序: https : //developers.facebook.com/apps/创建您的应用程序以获取应用程序 ID。 Also don't forget to add your main domain in your settings.另外不要忘记在您的设置中添加您的主域。 Then copy this code on your site:然后将此代码复制到您的网站上:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId            : 'XXXXXXXXX',
      autoLogAppEvents : true,
      xfbml            : true,
      version          : 'v6.0'
    });
  };
</script>
<script async defer src="https://connect.facebook.net/de_DE/sdk.js"></script>

<script>
    $("#fb-share-button a").click(function(e){
        e.preventDefault();
        var url = window.location.href;

        FB.ui({
            method: 'share',
            href: url,
        }, function(response){});
    });
</script>

html: html:

<div id="fb-share-button">

    <a href="#" target="_blank" class="Facebook">
        <div class="inside">
            <i class="fa-facebook" style="color:#848484;font-size:16px;width:44px;height:44px;-webkit-border-radius: 50% 50% 50% 50%;-moz-border-radius: 50% 50% 50% 50%;border-radius: 50% 50% 50% 50%;line-height:44px;border-width:1px; border-style:solid;border-color:#848484;text-align:center;"></i>
            <div class="desc">Facebook</div>
        </div>
    </a>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM