0
「使用Facebook登錄」功能對我來說工作正常,但我的要求是從另一個鏈接點擊該按鈕並隱藏實際按鈕。點擊「使用Facebook登錄」div通過javascript中的其他鏈接按鈕
我沒有得到哪個控件ID,我應該採取點擊「登錄與Facebook」div從JavaScript或jQuery。
<head>
<title>Facebook Login Authentication</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
// 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));
// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId: '6082xxxxxxxxxxxxx', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function (response) {
if (response.authResponse) {
var uid = "http://graph.facebook.com/" + response.authResponse.userID + "/picture";
// user has auth'd your app and is logged into Facebook
FB.api('/me', { locale: 'tr_TR', fields: 'name, email' },
function (response) {
document.getElementById('auth-displayname').innerHTML = response.name;
document.getElementById('Email').innerHTML = response.email;
document.getElementById('profileImg').src = uid;
}
);
document.getElementById('auth-loggedout').style.display = 'none';
document.getElementById('auth-loggedin').style.display = 'block';
} else {
// user has not auth'd your app, or is not logged into Facebook
document.getElementById('auth-loggedout').style.display = 'block';
document.getElementById('auth-loggedin').style.display = 'none';
}
});
$("#auth-logoutlink").click(function() { FB.logout(function() { window.location.reload(); }); });
}
function ClickFacebookLogin() {
//$('#auth-loggedout').trigger('click');
var myEl = document.getElementById('FBdiv');
myEl.click();
}
</script>
<h1>
Facebook Login Authentication Example</h1>
<div id="auth-status">
<div id="auth-loggedout">
<div class="fb-login-button" autologoutlink="true" scope="email" id="FBdiv">Login with Facebook</div>
</div>
<a onclick="ClickFacebookLogin();">Click FB</a>
<div id="auth-loggedin" style="display: none">
Hi, <span id="auth-displayname"></span>(<a href="#" id="auth-logoutlink">logout</a><br />
Email: <b><span id="Email"></span></b><br />
Profile Image: <img id="profileImg" />
</div>
</div>
</body>
這聽起來很可疑,你究竟想幹什麼?請查看http://stackoverflow.com/help/mcve以獲取有關如何創建最小,完整和可驗證示例的信息。 – Psi
只要不使用登錄按鈕插件,但調用的FB.login ... – CBroe