这似乎是一个简单的问题,其他人已经发布了,但我仍然无法找到答案。具体来说,我经历过这两个(这里和这里)SO问题,我只是没有与我的情况联系起来。
对我来说,我想我会将登录按钮包装在一个 div 中,然后根据登录状态更改 div 的可见性。div 确实改变了可见性,但 fb 登录按钮仍然可见???
这是我在 div 中包装登录按钮的代码:
....snip....
<div id="fblogin">
<table align="center" style="text-align:center;">
<tr>........</tr>
<tr>
<td>
<div id="fb-root"></div>
<span id="fb-login">
<div
class="fb-login-button"
onlogin="afterFbLogin()"
data-show-faces="false"
data-width="200"
data-max-rows="1"
data-scope="publish_stream">
</div>
</span>
............snip.............
这是我的 FB.Init 并检查登录状态:
window.fbAsyncInit = function () {
FB.init({
appId: '352810974851050', // App ID
channelUrl: '//www.domain.com/channel.html',
status: true, // check login status
cookie: true, // enable cookies
xfbml: true // parse page for xfbml or html5 like login button below
});
// Put additional init code here
FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
ShowFbLogin(false);
} else if (response.status === 'not_authorized')
.........snip...................
以及 ShowFbLogin 函数的 js 代码
function ShowFbLogin(ShowLogin)
{
var div_FBLogin = document.getElementById('fblogin');
var spn_FBLogin = document.getElementById('fb-login');
var div_FBShare = document.getElementById('fbshare');
if (ShowLogin)
{
div_FBLogin.style.visibility = 'visible';
div_FBShare.style.visibility = 'hidden';
}
else
{
div_FBLogin.style.visibility = 'collapse';
spn_FBLogin.style.visibility = 'collapse';
div_FBShare.style.visibility = 'visible';
}
}