我正在尝试在我的脸书中实施Facebook登录 这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Facebook Login JavaScript Example</title>
<meta charset="UTF-8">
</head>
<body>
<script>
function statusChangeCallback(response) {
if (response.status === 'connected') {
window.location = "welcome.html";
} else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : XXXXXXXXXXXXXX,
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.0' // use version 2.0
});
FB.Event.subscribe('auth.login', function () {
alert("authlogin subscription");
window.location = "welcome.html";
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<a href="#" onclick="checkLoginState();">FB Login</a>
</body>
</html>
成功登录后,我无法重定向到welcome.html,就好像我点击登录按钮已经登录用户可以重定向到welcome.html。 我无法在FB.Login()之后找到重定向的原因。