facebook - FB.XFBML.parse 在 IE 中不起作用

标签 facebook internet-explorer xfbml facebook-javascript-sdk

您好,我正在我的网站上使用 Facebook Like 按钮。我的所有内容都是通过 ajax 加载的,我知道如果您想使用 facebook 之类的按钮和 ajax 加载的内容,您应该使用 FB.XFBML.parse()。我用过这个,它在 Firefox 和 chrome 中运行良好,但在 IE 中不起作用。我正在检查 IE 8。我搜索了解决方案并发现here在我的 html 标记中添加 xmlns:fb="http://www.facebook.com/2008/fbml" 。我做到了,但还没有修复。我的代码看起来像

  layout.php

 <div id="fb-root" style="display:none"></div>
    <script>
        window.fbAsyncInit = function() {
        FB.init({
          appId      : 'APPID', // App ID
          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
      };

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

    </script>

这就是我使用 XFBML.parse

 $(".fblike").each(function(){
  FB.XFBML.parse($(this).get(0));
  //because having multiple likes button on same page.
});

这是我的“赞”按钮

 <div class='fblike'><fb:like send='false' layout='button_count' width='100' show-faces='false' href='www.myurl.com?ref=facebook' ></fb:like></div>

如何使其兼容 IE8 和 IE9?我哪里错了以及如何解决这个问题?

问候,

最佳答案

根据我的经验,如果您尝试运行包含在此调用之前 Conceal 的内容的 FB.XFBML.parse(),它将无法在 IE 和 Firefox 上运行。

这不会起作用:

<div id="wrapper" style="display:none">
    <fb:like id="like_button" ... ...></fb:like>
</div>

<script>
FB.XFBML.parse(document.getElementById('like_button'), function() {
    $('#wrapper').show();
});
</script>

可以使用类似这样的东西:

<div id="wrapper" style="display:block; height:0px; overflow:hidden;">
    <fb:like id="like_button" ... ...></fb:like>
</div>

<script>
FB.XFBML.parse(document.getElementById('like_button'), function() {
    $('#wrapper').animate({height:'30px'}, 300) 
});
</script>

希望这对其他人有帮助。

关于facebook - FB.XFBML.parse 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11184968/

相关文章:

javascript - 如何在不使用ActiveX控件的情况下从应用程序中获取当前登录的用户名?

php - Facebook 多好友选择器在 iframe 中被切断

php - Flash、Facebook 和权限 - JS、PHP 或 AS3 SDK

android - Facebook 登录按钮崩溃应用程序没有错误消息

java - 如何在 Facebook 分享对话框中设置描述(你在想什么?)

javascript - jQuery 的 IE GIF/PNG 透明度问题

css - IE 9 边界半径不适用于 PIE.js

javascript - 更新 FB :Like URL Dynamically using JavaScript

facebook - 使用 FB.XFBML.parse 重新渲染 Facebook 插件

iphone - 对用于 iphone 应用程序编辑事件的旧 rest api 感到困惑?