The following FB.Login function works fine in desktop Chrome, FF, and Safari. But in mobile Safari (tested on an iPhone 4S), it hangs and does not return to the FB.login callback. I can also see this in the console when I use Safari and set the User Agent to "Safari iOS 4.3.3 - iPhone".
Is it because mobile Safari blocks popups? (FB.login triggers a popup dialog).
How do I fix this? Thanks.
function Login(returnLink) {
FB.login(function(response) {
if(response.status === 'connected') {
console.log('User is now FB logged in.');
// now log them into my site
encodedReturnLink = encodeURIComponent(returnLink);
window.location = location.protocol + '//' + location.host + "/login?returnUrl=" + encodedReturnLink;
}
else {
console.log('User did not fully authorize after clicking FB login button.');
}
},
{scope : 'email, publish_actions, publish_stream'}
);
}
If you have no trouble logging into Facebook via Safari, try closing your Facebook app and restart again. To do so, double press your home button and swipe upwards on the Facebook thumbnail. The reopen your Facebook and try again.
By going into the Facebook app and options, scroll down to 'Help and Settings' and go into 'app settings. ' Turn on 'Links open externally' so that the next time you open up a link, it will go to your default browser instead of opening within Facebook.
Try refreshing your browser or reopening the site; on a mobile app, close and reopen the app. You can also check to see if Facebook is offline and then restart your device, update apps, and clear your cache.
If you use Safari as your primary browser on your iPhone, it's easy to get this browser to load Facebook's computer version. To start, launch Safari on your iPhone and access the Facebook site. It'll load the mobile version.
I was trying to run FB.Login automatically on page load inside window.fbAsyncInit and it wasn't working in Safari on iOS. It turns out Safari was blocking the popup window triggered by the FB.Login call. Safari and Chrome on the desktop worked fine (allowed the popup).
I found the only way to work-around this was to trigger the FB.Login call in response to user interaction (eg. Tap or Click). This worked for me:
HTML
<a href="#" id="fbLogin">Login with Facebook</a>
JavaScript (jQuery)
$('#fbLogin').click(function(){
FB.login(function(response){
// Do something...
});
});
Tested on Safari (iOS 8.0).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With