Facebook分享按钮无法打开对话框

时间:2016-08-11 09:56:03

标签: javascript jquery facebook

我正在尝试制作Facebook分享按钮。问题是当我点击按钮时它没有打开任何东西。不打开共享对话框窗口。这就是我所拥有的。我的按钮

<a class="share-fb" href="javascript:void(0);" onclick="shareFB( encodeURIComponent(\'http://example.com/'.$url.'\'), '.$row['image_title'].', encodeURIComponent(\'http://example.com/\') );"></a>

js部分

<div id="fb-root"></div>
    <script type="text/javascript">

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

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

        var lang        = 'BG';
        var prPath      = '/';
        var prjUrl      = 'http://example.com/';
        var fpath       = 'http://example.com/';            
        var PROTOCOL    = 'http://';            
        var SESSION     = '';           

        // Preload some heavy images if necessarilly 
        var preload = [

        ];

        var ploaded = [];

        $(preload).each(function(i, r){
            ploaded[i]      = new Image();
            ploaded[i].src  = '/img/'+r;
        });

        function shareFB(url,title,img)
        {
            if(!title) title = '';
            var i = (img) ? unescape(img) : 'http://example.com/img/logo.png';
            FB.ui({
                method: 'feed',
                name: title,
                description: 'description',
                caption:'wwww.example.com',
                picture: i,
                link: unescape(url)
            },function(r){});
            return false;
        }                       
    </script>

我得到的控制台中的错误是Uncaught SyntaxError: missing ) after argument list,但我看不出这个)在哪里丢失..

CSS

#gallery-nav span a.share-fb {
     background: url("../img/fb.png") no-repeat center center;
     background-size: contain;
}

以下是我在按钮代码中生成URI组件的方法:

$url = 'category-'.$row['img_category'].'/image-'.$row['image_id'].'.html'

<a class="share-fb" href="javascript:void(0);" onclick="shareFB( encodeURIComponent(\'http://example.com/'.$url.'\'), '.$row['image_title'].', encodeURIComponent(\'http://example.com/\') );"></a>

JS + CSS就在上面..

HTML输出

<a class="share-fb" href="javascript:void(0);" onclick="shareFB( encodeURIComponent('http://example.com/category-2/image-828.html'), image title, encodeURIComponent('http://example.com/') );"></a>

2 个答案:

答案 0 :(得分:1)

问题出在onclick,使用以下代码即可。调整变量以符合此模式。

<a class="share-fb" href="javascript:void(0);" onclick="shareFB( encodeURIComponent(''), '', encodeURIComponent('') );"></a>

答案 1 :(得分:-1)

},函数(r)的{});缺少&#34;)&#34; }),函数(r)的{});