google-app-engine - 检测到错误 : "popup_blocked_by_browser" for google auth2 in javascript

标签 google-app-engine popup popup-blocker

经过大量谷歌搜索后没有找到如何捕获 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/

相关文章:

google-app-engine - 应用引擎 : Unable to update app: Failed to compile jsp files

javascript - 如何从 javascript 中找到模态对话框开启器?

到达某个页面后弹出浏览器返回父浏览器

google-app-engine - 从 Objectify 实体获取随机条目

google-app-engine - 谷歌应用引擎 JDO 3

python - 如何在第二代应用程序引擎上下载 Spacy 模型?

javascript - 停止子 DIV 从其父页面继承样式

javascript - 如何测试命名窗口是否打开或被弹出窗口阻止程序阻止?

asp.net - 如果我希望单击“有时”仅打开一个新窗口,我可以避免进行同步回调吗?

javascript - 发生自动 session 超时时绕过浏览器弹出窗口阻止