简体   繁体   English

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

[英]Facebook share button doesn't open dialog

I'm trying to make facebook share button. 我正在尝试使Facebook分享按钮。 Problem is when I click on the button it doesn't open anything. 问题是,当我单击按钮时,它没有打开任何东西。 Doesn't open share dialog window. 不打开共享对话框窗口。 Here is what I have. 这就是我所拥有的。 My button 我的按钮

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

The js part 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>

The error in console that I've got is Uncaught SyntaxError: missing ) after argument list but I can't see where is this ) missing.. 我在控制台中遇到的错误是Uncaught SyntaxError: missing ) after argument list但我看不到这是哪里)

CSS 的CSS

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

Here is how I generate the URI Component in the button code: 这是我在按钮代码中生成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>

And the JS + CSS is above.. 上面是JS + CSS。

HTML output 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>

The problem is in your onclick , using the following code will work. 问题出在您的onclick ,使用下面的代码将起作用。 Adjust your variables to conform to this pattern. 调整变量以符合此模式。


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

},function(r){}); },function(r){}); there is missing ")" }),function(r){}); 缺少“)”}),function(r){});

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

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