我正在尝试通过我的网络应用程序构建 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/