简体   繁体   English

Facebook Javascript SDK无法启动Internet Explorer

[英]Facebook Javascript SDK not firing Internet Explorer

Let me start by saying that I am running this on port 80 on a web server, so that is not the reason why this code will not fire on internet explorer . 首先,我要在Web服务器的端口80上运行此代码,因此这不是此代码无法在Internet Explorer上触发的原因

This code works perfectly in Firefox, Chrome, and Safari. 此代码可在Firefox,Chrome和Safari中完美运行。 However, when I try to run it using Internet Explorer I get nothing but a big blank screen. 但是,当我尝试使用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>

` `

I just opened this in Internet Explorer 9 and it worked perfectly. 我刚刚在Internet Explorer 9中打开了它,它运行良好。 I logged in on Facebook, added the app, and it loaded the content. 我登录了Facebook,添加了应用程序,然后加载了内容。

Have you checked your IE settings? 您检查过IE设置了吗? Make sure it is set to allow javascript. 确保将其设置为允许javascript。

Same issue here I finally did the following: rather than use: 在这里,同样的问题我最终做了以下事情:而不是使用:

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

i use the following: 我使用以下内容:

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

Hope this helps! 希望这可以帮助!

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

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