繁体   English   中英

Facebook与JavaScript的SDK连接无法在IE浏览器?

[英]facebook connect with javascript sdk is not working in IE?

我已经使用javascript sdk为我的网站开发了一个facebook connect应用。 它适用于除IE之外的所有浏览器。

在IE中,有时它不调用用户单击“登录”按钮的测试API函数。 登录窗口弹出,当用户输入用户名和密码时,应调用testAPI函数。 但是有时函数调用将不起作用。 但是有时候,如果我刷新浏览器然后再试一次,它将起作用。

这里有人遇到这种问题吗? 以下是我的JavaScript代码:

window.fbAsyncInit = function() {
    FB.init({
      appId      : '', // App ID
      channelUrl : '//localhost/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });
    FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
      // connected
      testAPI();
    } else if (response.status === 'not_authorized') {
      // not_authorized
      login();
    } else {
      // not_logged_in
      login();
    }
  });

    // Additional init code here

  };



  function login() { //alert("test");
    FB.login(function(response) {
        if (response.authResponse) {
            // connected
          testAPI();
        } else {
            // cancelled
        }
    }, { scope: 'email' });
    }

  function testAPI() {
    //document.write ("tet");
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {

        //document.write("sdfs");
        //document.write(response.name);
        var test = response.first_name; //alert(test);
        console.log('Good to see you, ' + response.first_name + '.');
        console.log('Good to see you, ' + response.last_name + '.');
        console.log('Good to see you, ' + response.id + '.');
        console.log('Good to see you, ' + response.email + '.');
       // console.log(response);
    });
  }

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

好了,问题是IE不支持控制台对象,而愚蠢的事情是,如果您打开Internet Explorer开发人员工具,则支持控制台对象。

因此,只需删除所有console.log行,当您打开开发人员工具时它们就会起作用,但是如果关闭开发人员工具则它们将无法工作。 这是如此愚蠢,以至于很难调试。

而是尝试使用警报。

您可以在此处阅读更好的解释:

IE9是否支持console.log,它是真正的功能吗?

暂无
暂无

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

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