首页 > 解决方案 > 如何等到用户单击接受/取消按钮或关闭授权窗口

问题描述

在用户允许我们获取他的个人资料详细信息之后,我正在弹出窗口中打开一个用于 LinkedIn 授权的 URL。我想复制窗口 URL 并将其重定向回父窗口。

我知道我们如何获取窗口 URL,但在努力等待用户取消授权或允许然后获取窗口 URL。关于如何实现这一点的任何线索?

想要获取窗口 URL,因为它包含访问代码,可进一步用于使用 LinkedIn API 检索用户详细信息。

function myFunction() {
  // The url is opened in new pop up window, then user enter his credentials & gets a authorization window with allow & cancel button. 
  var win = window.open("https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=XXX&redirect_uri=XXX&state=aRandomString&scope=r_emailaddress", "LinkedIn Authorization", 'height=700,width=900');

  // Before printing the console log, I want to wait for the above line of code to either wait for close/allow/cancel button to be clicked on the authorization.
  console.log(win.location.href);
}
<button onclick="myFunction()">LinkedIn connect</button>

标签: javascripthtml

解决方案


推荐阅读