javascript - 使用 instagram 为 oauth 捕获弹出窗口关闭

标签 javascript instagram

相关问题:OAuth (Instagram) without refresh

现状

Instagram 需要完整的身份验证重定向,然后他们会重定向回来。我希望它与弹出窗口一起使用。

可能的解决方案

在弹出窗口中打开页面:

var authWindow = window.open(instagramUrl, 'authWindow');

然后我会让 instagram 重定向到一个自行关闭的页面:

<script>window.close()</script>

问题

我不知道如何知道窗口何时关闭。以下两者均无效:

authWindow.onbeforeunload = function() {
   window.opener.console.log('Closing popup!');
};

function logClose(cnsl) { cnsl.log('Closing popup!'); }
var callback = _.bind(logClose, window, console);
$(authWindow.document).click(callback);

替代建议非常欢迎!

最佳答案

而不是使用 <script>window.close()</script>直接地,你可以在父窗口中调用一个函数 window.opener然后关闭窗口:

家长:

function onInstagramAuth()
{
  // Handle however you would like here
  console.log('authenticated');
}

child :

try { window.opener.onInstagramAuth(); } catch (err) {}
window.close();

关于javascript - 使用 instagram 为 oauth 捕获弹出窗口关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17751955/

相关文章:

instagram - Instagram oEmbed 响应的thumbnail_url 错误

python - 使用 Python 将图像上传到 Instagram

javascript - 如果在 iOS 7 上的 "capable"webapp 中,则向 <body> 添加一个类

javascript - 如何在没有重定向 url 的情况下验证 instagram?没有服务器

javascript - 停止浏览器存储访问历史

JavaScript 代替重复的 HTML 行

android - 如何从帖子的链接从 instagram 下载图片和视频

javascript - Instagram API 的用户 obj 问题

javascript - 使用 break on click 停止循环

javascript - 声明后立即 undefined variable ?