javascript - 跨源窗口控制

标签 javascript oauth

我正在尝试通过我的网络应用程序构建 Google Plus 登录,就像您通过 oauth 弹出窗口在 foursquare.com 上看到的那样。该应用程序在控制台中显示以下错误。

Uncaught SecurityError: Blocked a frame with origin "http://airus.com:3000" from accessing a frame with origin "https://accounts.google.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

<script type="text/javascript">
    var REDIRECT    =   'http://airus.com/users/auth/google_oauth2/callback';
    function login(url, x) {
        var win         =   window.open(url, "windowname1", 'width=400, height=600'); 
        var pollTimer   =   window.setInterval(function() { 
            console.log(win.document.URL);
            if (win.document.URL.indexOf(REDIRECT) != -1) {
                window.clearInterval(pollTimer);
                var url =   win.document.URL;
                win.close();
                x.reload();
            }
        }, 500);
    }
    $("#link").click(function(){
        x = location;
        login($(this).attr('href'), x);
        return false;
    })
</script>

知道如何解决吗?

最佳答案

错误消息实际上是正确的:

The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

因此您必须通过 https(SSL,端口 443)为您的网站提供服务。这样你的页面的url就变成https://airus.com (:443)

关于javascript - 跨源窗口控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055824/

相关文章:

php - 在未授权用户的情况下搜索 LinkedIn API

php - 如何获得 facebook 应用程序的 publish_stream 权限?

spring boot oauth2.0 和 spring 安全 : How to grant permission(authorities) to user login via facebook or slack

oauth - facebook "Valid OAuth Redirect URIs"中不允许重定向 URI

javascript - 如何在另一个点击函数中覆盖 Ajax 成功数据

javascript - 在 HTML 超链接标记的 onClick 中调用 JavaScript 函数 ping() 导致 TypeError

javascript - jquery ajax 按名称发布选择框数组

php - 使用访问 token 获取 Twitter 用户名

javascript - 静态 D3 力导向图性能

方法调用模式中的 Javascript "this"指针未指向对象