Facebook 登录(身份验证)表单在 Google Chrome 中被阻止(并非总是如此,但有时)。
fb 的 HTML 内容
<a href='javascript:void(0);' id='facebook'><img src='fblogimage'></a>
在 .js 文件中
$("#facebook").click(function ()
{
Facebook.authenticate(function () {
Login.hidePopup();
});
});
Facebook.authenticate = function (callback)
{
FB.getLoginStatus(function (response) {
if (response.status === 'connected')
{
// -- success process
}
else
{
FB.login(function (loginResponse)
{
if (loginResponse.status === 'connected')
{
Facebook.setUserName();
Facebook.fbApi(loginResponse, callback);
}
},
{
scope: 'user_friends, publish_stream, email, user_location,
user_mobile_phone'
});
}
});
}
它可以在 FF 和 IE 中运行,但不能在 Google Chrome 中运行(弹出窗口阻止)
请帮忙解决。
最佳答案
我在多个浏览器中都遇到了这个问题,而不仅仅是 Chrome。事实证明,您必须通过单击按钮调用登录弹出窗口。
这里引用 the documentation (强调):
As noted in the reference docs for this function, it results in a popup window showing the Login dialog, and therefore should only be invoked as a result of someone clicking an HTML button (so that the popup isn't blocked by browsers).
您的代码可能因使用 <a href='javascript:void(0);'
而出现问题而不是<button>
或有效的链接(例如 <a href="#">
或类似的链接)。
希望这对某人有帮助!
关于javascript - Facebook 身份验证在 Chrome 中被阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29926743/