我对 Stackoverflow 和编码很陌生,但我会尽力使这个问题尽可能清晰和简单:
我正在寻找一个网页,其中有一个 Facebook Like 按钮和一个 Logout 按钮,可以让用户退出 Facebook 帐户......所以用户可以 Facebook Like,输入登录信息,然后注销。这是我到目前为止的脚本,但我已经刷新以便注销工作并直接返回主页。非常感谢您的帮助:
互动链接:http: //jsfiddle.net/nrdnx/11/
代码:
<html>
<head>
<title>My Great Web page</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '271358172932770', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
getStatus();
};
// 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>
</script>
<iframe src="http://www.facebook.com/plugins/like.php?href=www.facebook.com/orangeleaflawrence"
scrolling="no" frameborder="0"
style="border:none; width:450px; height:80px"></iframe>
<a href="javascript:void();" onclick="getStatus()">Get Status</a>
<div id="logout"><a href="logout.html">Logout of Facebook</a></div>
<script>
FB.Event.subscribe('auth.authResponseChange', function(response) {
alert('The status of the session is: ' + response.status);
});
function getStatus(){
FB.getLoginStatus(function (response) {
alert(response.status);
if (response.status === 'connected') {
document.getElementById('logout').style.display='';
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
} else if (response.status === 'not_authorized') {
document.getElementById('logout').style.display='none';
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
document.getElementById('logout').style.display='none';
}
}
);
}
</script>
</body>
</html>
</p>