0

我在代码中使用的类似 Facebook 的按钮不起作用。我已经完成了所有必要的工作:将 JavaScript 代码放置在 body 标记下方,并将div它的另一个标记放置在我希望按钮出现的位置,但我没有成功。这是我的代码:

<head>
    <meta charset="UTF-8" />
    <title>Riparian Preserve Survey</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="bootstrap-responsive.min.css"type="text/css"/>
    <link rel="stylesheet" href="bootstrap.css" type="text/css"/>
    <script src="jquery-1.9.1.js"></script>
    <script src="bootstrap.min.js"></script>
    <script src="bootstrap.js"></script>

    <style>
        img {
            max-width: 100%;
        }
        body{
            background-color: #A4A4A4 ;
        }
    </style>
</head>
    <body> 
<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/all.js#xfbml=1";
   fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));</script>    
...
 <div class="fb-like" data-href="https://www.facebook.com/GilbertTownHall"data-  send="true" data-width="450" data-show-faces="false"></div>
4

2 回答 2

1

Facebook 使用我相信首先加载的 SDK,这是在他们的网站上,您尝试过吗?

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID',                        // App ID from the app dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // Load the SDK asynchronously
  (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/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>
于 2013-04-17T03:57:24.727 回答
0

试试这样的:

window.fbAsyncInit = function () {
    if (FB.init) return;
    // init the FB JS SDK
    FB.init({
        appId: 'YOUR_APP_ID', // App ID from the App
        //channelUrl: '//' + window.location.hostname + '/channel.html',
        //This to get the user details back from Facebook
        //scope: 'id,name,gender,user_birthday,email', etc
        status: true, // check the login status upon init?
        cookie: true, // set sessions cookies to allow your server to access the session?
        xfbml: true  // parse XFBML tags on this page?
    });
}

在 HTML 正文的末尾...

<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.async = true;
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
        fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
</script>

您也可以使用 fb 嵌入 iframe
Facebook Like Button Reference

于 2013-04-17T05:19:10.820 回答