1

関連する質問:更新なしの OAuth (Instagram)

状況

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);

代替提案は歓迎です!

4

1 に答える 1

6

直接使用する代わりに<script>window.close()</script>、親ウィンドウで関数を呼び出してからウィンドウをwindow.opener閉じることができます。

親:

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

子:

try { window.opener.onInstagramAuth(); } catch (err) {}
window.close();
于 2013-07-19T18:31:22.243 に答える