单击Like按钮时的事件

时间:2012-02-21 00:44:16

标签: facebook button facebook-like

单击LIKE按钮时,我无法执行任何操作。

这是我的剧本:

<html xmlns:fb="http://ogp.me/ns/fb#">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Caron mazda</title>
</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/fr_FR/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked THISSS Yeaa');
    }
);

 alert('I am an alert box!'); // dont work ?? probleme avec le edge.create !
</script>


<fb:like-box href="http://www.facebook.com/ConcessionnaireCaronMazda#!/ConcessionnaireCaronMazda" width="292" show_faces="false" stream="false" header="false"></fb:like-box>

</body>
</html>

你可以修改我的代码来举办活动吗?脚本有什么问题?

1 个答案:

答案 0 :(得分:1)

您尚未初始化SDK。只需使用Facebook默认实现:

<html xmlns:fb="http://ogp.me/ns/fb#">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Caron mazda</title>
</head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
    FB.Event.subscribe('edge.create',
        function(response) {
            alert('You liked THISSS Yeaa');
        }
    );
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

<fb:like-box href="http://www.facebook.com/ConcessionnaireCaronMazda#!/ConcessionnaireCaronMazda" width="292" show_faces="false" stream="false" header="false"></fb:like-box>

</body>
</html>