fb-login-button with welcome message
HTML
<html>
<head>
<title>My Facebook Login Page with listener</title>
</head>
<body>
<div id="fb-root"></div>
<div class="box">
<div class="info">
This is an example of a welcome back message
</div>
<div class="fb-login-button">Login with Facebook</div>
</div>
<div class="box">
<div id="name">
</div>
</div>
</body>
</html>
CSS
p {margin: 10px;color:#336699;}
.box {float:left; border:1px solid #222; padding:5px; margin: 5px;}
.info {color:#778999;font-style:italic;margin:5px 0;}
JavaScript
window.fbAsyncInit = function() {
FB.init({
appId: '113830492072210',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.getLoginStatus(function(response) {
if (response.status=='connected') {
FB.api('/me',function(response){
alert('Welcome back ' + response.name);
$('#name').html(response.name);
});
}
});
};
(function(d) {
var js, id = 'facebook-jssdk';
if (d.getElementById(id)) {
return;
}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));