繁体   English   中英

Facebook Javascript SDK无法启动Internet Explorer

[英]Facebook Javascript SDK not firing Internet Explorer

首先,我要在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>

`

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

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

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

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

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM