Hello I am using this function to login with facebook. Now browser prevents popup window to open and asks for permission. How to resolve it ? I can unserstand the issue is that browser takes this as non user event.
function chk_login()
{
window.fbAsyncInit = function() {
FB.init({appId: my_app_id, status: true, cookie: true, xfbml: true,oauth : true});
FB.getLoginStatus(function(response) {
if (response.authResponse) {
var fb_access_token = response.authResponse.accessToken;
FB.api('/me', function(response) {
console.log(response);
});
}
else
{
}
});
FB.login(function(response) {
if (response.authResponse) {
var fb_access_token = response.authResponse.accessToken;
FB.api('/me', function(response) {
console.log(response);
});
}
},{scope: fb_scope});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
}
<img src="fb_login.jpeg" onclick="chk_login()" alt="Facebook Login" style="cursor:pointer;"/>
Don’t wrap the whole SDK in your function, instead have your SDK initializing in the top of the page (after the
<body>tag) and put theFB.login()method in your login function. something like: