简体   繁体   English

FB.ui未定义

[英]FB.ui is not Defined

Using BugSnag, I can see that some of our users on our website are runnning into this error: 使用BugSnag,我可以看到我们网站上的某些用户遇到了此错误:

FB.ui is not a function

When I visit the site and get to the page that this error is appearing, I have no issues. 当我访问该站点并转到出现此错误的页面时,我没有任何问题。

Here is our script to share to fb: 这是我们分享给fb的脚本:

<div id="fb-root"></div>
<script>
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.12&appId=1365705806909063&autoLogAppEvents=1';
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
</script>

<div class="x-custom-col" id="share-fb-btn">
    <a class="x-fb x-btn" data-social-type="fb-share" data-eventlabel="inlineshare">
        <i class="ico-facebook"></i>
        <span>Share to Facebook!</span>
    </a>
</div>

<script>
    document.getElementById('share-fb-btn').onclick = function() {
        FB.ui({
            method: 'share_open_graph',
            action_type: 'og.shares',
            action_properties: JSON.stringify({
                object: {
                    'og:url':"http://www.example.com/",
                    'og:title': "Here is some info to share!".",
                    'og:description': "Decribe it!",
                    'og:image': "https://www.example.com/image"
                }
            })
        },
        function (response) {
            // Action after response
        });
    }
</script>

It seems this is only happening on our mobile layout. 看来这仅发生在我们的移动版式上。 Any suggestions? 有什么建议么?

This can happen if someone uses a tool to block external scripts for social media and analytics. 如果有人使用工具阻止外部脚本进行社交媒体和分析,则可能会发生这种情况。 It blocks loading the script, so FB will not get initialized and FB.ui will not exist. 它阻止加载脚本,因此不会初始化FB,并且FB.ui将不存在。

You can solve this by checking if FB exists, or by adding the click listener in the window.fbAsyncInit callback of the JavaScript SDK. 您可以通过检查FB是否存在或在JavaScript SDK的window.fbAsyncInit回调中添加单击侦听器来解决此问题。

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

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