2014-10-05 47 views
0

我的代码:为什么不是与jquery/fb js共享按钮出现?

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    <script> 
     $(document).ready(function() { 
     $.ajaxSetup({ cache: true }); 
     $.getScript('//connect.facebook.net/en_UK/all.js'); 
     }); 
    </script> 
    </head> 

    <body> 
    <div class="fb-share-button" data-href="https://www.google.com/" data-layout="button_count"></div></p> 
    </body> 
</html> 

一个演示:

http://www.frostjedi.com/terra/scripts/demo/fb1.html

份额按钮并未显示和IDK的原因。有任何想法吗?

的代码是基于关闭的https://developers.facebook.com/docs/javascript/howto/jquery除了API密钥不被设置(虽然我不想象应该有所作为)

+0

使用https://developers.facebook.com/docs/plugins/share-button – 2014-10-05 17:04:06

+0

我维托里诺同意。不要为此使用jquery,只需使用他发布的链接中生成的代码即可。 – luschn 2014-10-05 17:18:32

+0

它不起作用,因为你没有调用FB.init – WizKid 2014-10-06 03:02:28

回答

0

您正在使用Facebook的脚本错误的URL。更改为: $.getScript('//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0');

顺便说一句,你真的不需要这个jQuery。同样的结果可以用下面的代码来达到:

<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 = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk'));</script> 
<div class="fb-share-button" data-href="https://www.google.com/" data-layout="button_count"></div> 
相关问题