javascript - capture popup window close for oauth with instagram - Stack Overflow

Related question: OAuth (Instagram) without refreshThe SituationInstagram expects a full redirect for a

Related question: OAuth (Instagram) without refresh

The Situation

Instagram expects a full redirect for authentication, and then they'll redirect back. I want it to work with a popup.

Possible Solution

Open the page in a popup:

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

Then I'll have instagram redirect to a page that closes itself:

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

The Problem

I can't figure out how to find out when the window is closed. The following both don't work:

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

Alternative suggestions are very wele!

Related question: OAuth (Instagram) without refresh

The Situation

Instagram expects a full redirect for authentication, and then they'll redirect back. I want it to work with a popup.

Possible Solution

Open the page in a popup:

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

Then I'll have instagram redirect to a page that closes itself:

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

The Problem

I can't figure out how to find out when the window is closed. The following both don't work:

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

Alternative suggestions are very wele!

Share Improve this question edited May 23, 2017 at 11:59 CommunityBot 11 silver badge asked Jul 19, 2013 at 17:18 AJcodezAJcodez 34.4k20 gold badges87 silver badges118 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Instead of using <script>window.close()</script> directly, you could call a function in the parent window with window.opener and then close the window:

Parent:

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

Child:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745186647a4615670.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信