Plugins 如何从getLoginStatus()函数内部更改fb:registration标记可见性

Plugins 如何从getLoginStatus()函数内部更改fb:registration标记可见性,plugins,facebook-javascript-sdk,registration,facebook-login,Plugins,Facebook Javascript Sdk,Registration,Facebook Login,这就是我设置登录/注册流程的方式。在index.html页面上有一个链接。单击后,您将被发送到第二个页面,其中您的登录状态被选中,如果您未注册或登录,则会显示fb登录/注册框。 我所做的是使标签在页面上不可见,直到检查登录状态之后?一旦它被选中,我希望它成为可见的,如果用户没有登录或注册,但它不会变得可见。 在选中登录状态之前,隐藏“注册/登录”框可见性的最佳方法是什么。我不想使用facebooks login()函数,因为我不想要弹出窗口。我想使用XFBML标记。下面是我的代码: <!D

这就是我设置登录/注册流程的方式。在index.html页面上有一个链接。单击后,您将被发送到第二个页面,其中您的登录状态被选中,如果您未注册或登录,则会显示fb登录/注册框。 我所做的是使标签在页面上不可见,直到检查登录状态之后?一旦它被选中,我希望它成为可见的,如果用户没有登录或注册,但它不会变得可见。 在选中登录状态之前,隐藏“注册/登录”框可见性的最佳方法是什么。我不想使用facebooks login()函数,因为我不想要弹出窗口。我想使用XFBML标记。下面是我的代码:

<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script >
  <base href="http://spilot.koding.com/">


  </script>
</head>
<body>
<div id="fb-root"></div>
<script>


  // Additional JS functions here
 window.fbAsyncInit = function() {
    FB.init({
      appId      : '3967205****88', // App ID
      channelUrl : '//http://spilot.koding.com/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
    });


    // get login status

FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // connected
  } else if (response.status === 'not_authorized') {
    // not_authorized


        document.getElementByName("login").style.visibility = visible;

  } else {
    // not_logged_in

      document.getElementByName("login").style.visibility = visible;

  }
 });
  };



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



</script>


<div id="fb-root" name="login" style="visibility:hidden">
<script src="https://connect.facebook.net/en_US/all.js#appId=396720557089188&xfbml=1"></script>

<fb:registration 
  fields="name,birthday,gender,location,email" 
  redirect-uri="http://spilot.koding.com/signedRequest.php" width="530">
</fb:registration> 
</div>

</body>
</html>

//这里有额外的JS函数
window.fbAsyninit=函数(){
FB.init({
appId:'3967205****88',//应用ID
频道URL:'//http://spilot.koding.com/channel.html“,//通道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
//获取登录状态
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
//连接的
}else if(response.status===“未授权”){
//未经授权
document.getElementByName(“login”).style.visibility=可见;
}否则{
//未登录
document.getElementByName(“login”).style.visibility=可见;
}
});
};
//异步加载SDK
(职能(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);
}(文件);

这是对我有效的解决方案。我决定改用注册插件。我将iframe放在一个div中,并将div的可见性设置为“hidden”,然后在检查登录状态的init代码中,调用一个使用document.getElementById().style.visibility=“visible”的函数来获取div并更改其可见性。确保所有需要引用的东西都有它们,这是我最初的错误之一

<!DOCTYPE html>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
  <script >
  <base href="http://spilot.koding.com/">


  </script>
</head>
<body>
<div id="fb-root"></div>
<script>


  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '396720557******', // App ID
      channelUrl : '//http://spilot.koding.com/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
    });

    // Additional init code here
    FB.getLoginStatus(function(response) {
  if (response.status === 'connected') {
    // connected

  } else if (response.status === 'not_authorized') {
    // not_authorized
    ///log function will change div visibility to "visible"
   log();

  } else {
    // not_logged_in
   log();

  }
 });//closes fb.getLoginStatus
  };// closes fbAsyncInit


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

  //change div visibility to visible

  var log = function(){
     document.getElementById('login').style.visibility = "visible";


  }//closes function log()
</script>

//put iframe inside a div and set the div's visibility to hidden. 

<div id ="login" style = "visibility:hidden" >
<iframe src="https://www.facebook.com/plugins/registration?
             client_id=396720557089188&&
             redirect_uri=http://spilot.koding.com/signedRequest.php&
             fields=name,birthday,gender,location,email"
        scrolling="auto"
        frameborder="no"
        style="border:none"
        allowTransparency="true"
        width="100%"
        height="330">
 </iframe>

    </div>





</body>
</html>

//这里有额外的JS函数
window.fbAsyninit=函数(){
FB.init({
appId:'396720557*****',//应用程序ID
频道URL:'//http://spilot.koding.com/channel.html“,//通道文件
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
//这里有额外的初始化代码
FB.getLoginStatus(函数(响应){
如果(response.status===“已连接”){
//连接的
}else if(response.status===“未授权”){
//未经授权
///日志函数将div可见性更改为“可见”
log();
}否则{
//未登录
log();
}
});//关闭fb.getLoginStatus
};// 关闭FBAsyninit
//异步加载SDK
(职能(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);
}(文件);
//将div可见性更改为visible
var log=函数(){
document.getElementById('login').style.visibility=“visible”;
}//关闭函数日志()
//将iframe放在div中,并将div的可见性设置为hidden。

fb root的结束标记在哪里。还有,为什么不在
fb:registration
标记周围再加一个div,然后显示/隐藏这个div呢?