Facebook喜欢按钮不显示document.write();

时间:2012-10-31 03:05:56

标签: javascript facebook

我有一个示例代码:

<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <head>
    <script language="javascript" type="text/javascript">
    window.checkDoesLike = function() {
      FB.api({ method: 'pages.isFan', page_id: '40796308305' }, function(resp) {
        if (resp) {
            alert("You have like this pages");
        } else {
            //<![CDATA[
            document.write('<fb:like href="http://www.facebook.com/coca-cola" layout="button_count" show_faces="false" width="450" action="like" font="arial" colorscheme="light"></fb:like>');
            //]]>
        }
      });
    };
    </script>
  </head>
  <body onload="checkDoesLike()">
    <div id="fb-root"></div>
    <script language="javascript" type="text/javascript">
    // Load the SDK Asynchronously
    (function(d){
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
    }(document));
    </script>
  </body>
</html>

当我运行代码时,facebook就像没有显示(虽然我不喜欢页面http://www.facebook.com/coca-cola),但是如何修复它?

1 个答案:

答案 0 :(得分:0)

在向页面添加XFBML标记后,您需要调用FB.XFBML.parse()