ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript – Google SignIn按钮被阻止的框架

2019-05-29 11:19:54  阅读:242  来源: 互联网

标签:javascript google-chrome google-plus


我一直在尝试使用Google SignIn构建一种Hello World项目.我在https://developers.google.com/+/web/signin/跟随教程,我的(摘录)代码是:

...
<script>
        function signinCallback(authResult) {
        //location.reload();
        //var x = 0
        //while(x=0){
            if (authResult['access_token']) {
                // Successfully authorized
                 // Hide the sign-in button now that the user is authorized, for example:
                 document.getElementById('signinButton').setAttribute('style', 'display: none');
                //document.getElementById("secret").innerHTML = ("<a href="secret.html"><p>Non-Conspicuous Link to Super Secret Page</p></a>");
                //alert("IT WORKED");
                document.getElementById("secret").innerHTML=("Non-Conspicuous Link to Super Secret Page");
                document.getElementById("game").innerHTML=("Non-Conspicuous Link to Super Secret Game Page");
                document.getElementById('refresh').setAttribute('style', 'display: none');
                //alert("Please Refresh");
                 } else if (authResult['error']) {
                 // There was an error.
                 // Possible error codes:
                 //   "access_denied" - User denied access to your app
                 //   "immediate_failed" - Could not automatically log in the user
                 console.log('AuthERROR: ' + authResult['error']);
                //alert("ERROR: A team of poorly trained robots has been dispatched to handle the situation. If they arive, tell them '" + authResult['error'] + "'");
              }
            }
        </script>
...
<span id="signinButton">
        <span 
            class="g-signin"
            data-callback="signinCallback"
            data-clientid="CLIENT ID"
            data-cookiepolicy="single_host_origin"
            data-requestvisibleactions="http://schemas.google.com/AddActivity"
            data-scope="https://www.googleapis.com/auth/plus.login"
            data-width="wide"
            data-theme="light">
        </span>
...
<a href="secret.html"><p id="secret"></p></a>
...

当我在Google Chrome(版本29.0.1547.18 dev-m)中运行代码时,出现此错误:

Blocked a frame with origin "https://accounts.google.com" from accessing a frame with origin "https://apis.google.com". Protocols, domains, and ports must match.

我的signinCallback函数中的代码在页面的第一次加载时被调用,但是当按钮用于登录时不会运行.在重新加载页面之前不会执行代码.

但是,在Firefox中不会出现此问题,因此它似乎是与Chrome隔离的错误.我还没有测试过任何其他浏览器.

反正有没有解决这个问题?

谢谢!

解决方法:

即使使用https,我正在调整java混合服务器端流程quick-start app并出现“阻塞帧”错误.我发现这个错误是由这个javascript客户端代码块触发的(在onSignInCallback函数中):

for (var field in authResult) {
  $('#authResult').append(' ' + field + ': ' +
      authResult[field] + '<br/>');
}

上面的代码是快速启动应用程序的一部分,仅用于教育目的.枚举或获取authResult对象中的某个字段时发生错误.删除上面的代码(或用try-catch块包围它)解决了这个问题.

标签:javascript,google-chrome,google-plus
来源: https://codeday.me/bug/20190529/1177568.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有