0

首先让我说我在 web 服务器上的端口 80 上运行它,所以这不是这个代码不会在 internet explorer 上触发的原因

此代码在 Firefox、Chrome 和 Safari 中完美运行。但是,当我尝试使用 Internet Explorer 运行它时,我只得到一个大的空白屏幕。

<link rel="stylesheet" type="text/css" href="styles/316127.css" />
<div id="fb-root"></div>
<div class="fb-login-button" data-show-faces="false" data-width="400" data-max-rows="1"     scope="email,friends_work_history,friends_location,user_work_history,user_location" id="loginButton" style="display: inherit;"> </div>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<body>

window.fbAsyncInit = function () {


    FB.init({
        appId: 'MYAPPID', // App ID
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        xfbml: true  // parse XFBML

    });

    FB.Event.subscribe('auth.authResponseChange', function (response) {
        if (response.status === 'connected') {

            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token
            // and signed request each expire


            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;

            var form = document.createElement("form");
            form.setAttribute("method", 'post');

            form.setAttribute("action", 'FacebookLogin.ashx');

            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", 'accessToken');
            field.setAttribute("value", accessToken);
            form.appendChild(field);

            document.body.appendChild(form);
            form.submit();

            //display loading logo

            document.getElementById('loadinggif').style.display = 'inherit';
            document.getElementById('loginButton').style.display = 'none';

        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook,
            // but has not authenticated your app

        } else {
            // the user isn't logged in to Facebook.

        }
    });
};

// 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));

<title>Test</title>

<form id="form1" runat="server">


 <br />

<asp:Image ID="loadinggif" runat="server" ImageUrl="~/Site/ajax-loader.gif" ImageAlign="Middle" style="display: none;" CssClass="centered"/>
</form>

`

4

2 回答 2

1

我刚刚在 Internet Explorer 9 中打开它,它运行良好。我登录 Facebook,添加应用程序,然后加载内容。

你检查过你的IE设置吗?确保将其设置为允许 javascript。

于 2012-09-13T05:37:24.037 回答
0

同样的问题,我终于做了以下事情:而不是使用:

  window.fbAsyncInit = function() {
    FB.init({
      appId:  'XXXXXX',
      status: true,
      cookie: true,
      xfbml: true
    });
  }

我使用以下内容:

  var fbAsyncLoaded=0;
  window.fbAsyncInit = function() {
    if(fbAsyncLoaded!=1) { fbAsyncLoaded=1; appInit(); }
  }

  if(document.addEventListener) 
  {
    document.addEventListener("DOMContentLoaded", function() {
      if(fbAsyncLoaded != 1) { fbAsyncLoaded=1; appInit(); }
      document.removeEventListener("DOMContentLoaded", arguments.callee, false);
    }, false );
  } else if(document.attachEvent) {
    document.attachEvent("onreadystatechange", function() {
      if(document.readyState === "complete") {
        if(fbAsyncLoaded != 1) { fbAsyncLoaded=1; appInit(); }
        document.detachEvent( "onreadystatechange", arguments.callee);
      }
    });
  }

  function appInit()
  {
    FB.init({
      appId:  'XXXXXX',
      status: true,
      cookie: true,
      xfbml: true
    });
  }

希望这可以帮助!

于 2013-01-23T16:15:15.340 回答