相关问题: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/