fb没有为fb共享对话框插件定义

时间:2021-11-03 19:40:26

I have included following code in footer file of my project:

我在我的项目的页脚文件中包含以下代码:

<script>
$(document).ready(function(){

  window.fbAsyncInit = function() {
    FB.init({
      appId      : '996999210390006',
      xfbml      : true,
      version    : 'v2.6'
    });
  };

  (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 = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));


});

function sharefbDialog()
{
    alert("fb");
    FB.ui({
          method: 'share',
          href: 'https://developers.facebook.com/docs/',
        }, function(response){});
}
</script>

Where i call sharefbDialog function onclick of anchor tag but it always gives fb not defined error. Initially I put fb.init code outside document.ready but even then it didn't work. I have look into all * solution but no success.

我在其中调用sharefbDialog函数onclick的锚标记,但它始终给fb未定义错误。最初我把fb.init代码放在document.ready之外,但即使这样它也不起作用。我已经研究了所有*解决方案,但没有成功。

1 个解决方案

#1


0  

you can also call the function this way.

你也可以用这种方式调用这个函数。

<html5>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>  
<script>
    window.fbAsyncInit = function() {
    FB.init({
      appId      : '996999210390006',
      xfbml      : true,
      version    : 'v2.6'
    });
    };

    (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 = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    function sharefbDialog()
    {
    alert("fb");
    FB.ui({
          method: 'share',
          href: 'https://developers.facebook.com/docs/',
        }, function(response){});
    }

    sharefbDialog();
</script>
<head>
    <body>
    <h2>Hello<h2>
        <a href="" onclick="sharefbDialog();" >Testing </a>
    </body>
</html5>

#1


0  

you can also call the function this way.

你也可以用这种方式调用这个函数。

<html5>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>  
<script>
    window.fbAsyncInit = function() {
    FB.init({
      appId      : '996999210390006',
      xfbml      : true,
      version    : 'v2.6'
    });
    };

    (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 = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    function sharefbDialog()
    {
    alert("fb");
    FB.ui({
          method: 'share',
          href: 'https://developers.facebook.com/docs/',
        }, function(response){});
    }

    sharefbDialog();
</script>
<head>
    <body>
    <h2>Hello<h2>
        <a href="" onclick="sharefbDialog();" >Testing </a>
    </body>
</html5>