Facebook FB.login适用于Safari,但不适用于移动Safari [英] Facebook FB.login works in Safari, but not mobile Safari

查看:179
本文介绍了Facebook FB.login适用于Safari,但不适用于移动Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下FB.Login功能在桌面Chrome,FF和Safari中正常工作。
但是在移动Safari(在iPhone 4S上测试),它挂起并且不返回FB.login回调。当我使用Safari并将用户代理设置为Safari iOS 4.3.3 - iPhone时,我也可以在控制台中看到这一点。



是因为移动Safari阻止弹出窗口吗? (FB.login触发弹出对话框)。



如何解决这个问题?谢谢。

 函数登录(returnLink){
FB.login(function(response){
if (response.status ==='connected'){
console.log('User is now FB logged in。');
//现在将它们记录到我的网站
encodedReturnLink = encodeURIComponent (returnLink);
window.location = location.protocol +'//'+ location.host +/ login?returnUrl =+ encodedReturnLink;
}
else {
console.log('用户点击FB登录按钮后没有完全授权。');
}
},
{scope:'email,publish_actions,publish_stream'}
) ;
}


解决方案

code> FB.Login 自动在 window.fbAsyncInit 中的页面加载,并且在iOS上的Safari中无法使用。事实证明,Safari正在阻止由FB.Login调用触发的弹出窗口。桌面上的Safari和Chrome工作正常(允许弹出)。



我发现解决方法是触发FB.Login调用以响应用户交互(例如点击或点击)。这对我有用:



HTML

 < a href =#id =fbLogin>使用Facebook登录< / a> 

JavaScript(jQuery)



$ $ $ $ $ $'$''''''''''''''''''''''''''' ..
});
});

在Safari(iOS 8.0)上测试。


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'}
        );
}

解决方案

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).

这篇关于Facebook FB.login适用于Safari,但不适用于移动Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆