0

這就是我設置我的登錄/註冊流程的方式。在index.html頁面上有一個鏈接。點擊後,您將被髮送到第二頁,在該頁面中您的登錄狀態將被檢查,並且如果您未註冊或登錄,將顯示fb登錄/註冊框。 我所做的是使標籤在頁面上不可見直到檢查登錄狀態之後?一旦檢查,我希望它變得可見,如果用戶沒有登錄或註冊,但它不可見。 在登錄狀態被選中之前,隱藏註冊/登錄框可見性的最佳方法是什麼?我不想使用facebooks login()函數,因爲我不想彈出一個窗口。我想使用XFBML標籤。以下是我的代碼:如何從裏面改變fb:註冊標籤的可見性getLoginStatus()函數

<!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> 
+0

「fb-root」的結束標記在哪裏?另外爲什麼不把另一個div包含在'fb:registration'標籤中並顯示/隱藏那個標籤? – 2013-03-07 19:36:47

回答

0

這是爲我工作的解決方案。我決定改用註冊插件。我把iframe放在一個div中,並將div的可見性設置爲「隱藏」,然後在檢查登錄狀態的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>