【问题标题】:capture popup window close for oauth with instagram使用 instagram 为 oauth 捕获弹出窗口关闭
【发布时间】:2013-07-26 05:09:31
【问题描述】:

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

非常欢迎其他建议!

【问题讨论】:

    标签: javascript instagram


    【解决方案1】:

    除了直接使用&lt;script&gt;window.close()&lt;/script&gt;之外,您还可以使用window.opener调用父窗口中的函数,然后关闭窗口:

    家长:

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

    孩子:

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

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 2012-01-08
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多