经过大量谷歌搜索后没有找到如何捕获 google auth2 的窗口弹出窗口阻止程序错误的解决方案
控制台报错:“popup_blocked_by_browser”。 我想要做的就是告诉用户应该为身份验证启用弹出窗口。
使用 window.open() 的示例并不好,因为它们会打开无用的窗口。 我看到很多人都在搜索这个。
有什么建议吗?
最佳答案
遇到了同样的问题。似乎浏览器(或至少 chrome)会阻止任何“window.open”调用,它不是作为用户交互的一部分被调用的。
引用here以获得更深入的解释。
__
我曾经在点击事件监听器中包含以下代码:
gapi.load('auth2', function() {
var auth2 = gapi.auth2.init({
client_id: '.apps.googleusercontent.com',
fetch_basic_profile: true,
scope: 'profile'
});
auth2.signIn()
.then(function() {
var profile = auth2.currentUser.get().getBasicProfile();
...
})
.catch(function(err) { ... });
});
请注意加载“auth2”的异步方式,这是 google docu 所说的。
我把它改成:
// way earlier, before click event can happen
// we call the gapi.load method.
gapi.load('auth2', function() {});
然后,在点击事件处理程序中,我们可以:
var auth2 = gapi.auth2.init({
client_id: '.apps.googleusercontent.com',
fetch_basic_profile: true,
scope: 'profile'
});
auth2.signIn()
.then(function() { ... })
.catch(function(err) { ... });
...所以浏览器不会阻止谷歌登录弹出
关于google-app-engine - 检测到错误 : "popup_blocked_by_browser" for google auth2 in javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45624572/