javascript - 如何等到用户单击接受/取消按钮或关闭授权窗口
问题描述
在用户允许我们获取他的个人资料详细信息之后,我正在弹出窗口中打开一个用于 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>
解决方案
推荐阅读
- reactjs - EsLint - 无法解析模块的路径
- wordpress - 联系表格 7 重定向问题
- math - 带 RoundingMode.HALF_UP 的 DecimalFormat
- vb.net - 直接流式方法 CopyTo 找不到结尾
- jsf - JSF SelectOneRadio PrimeFaces javax.el.PropertyNotFoundException:目标无法到达
- java - Java 从 USB 条形码扫描仪获取输入
- javascript - 如何使用 Google Chart 更改图例中的背景颜色?
- java - 将 Jackson、@JsonIdentityInfo 和 @JsonDeserialize 与 lombok Builder 一起使用时出现 MismatchedInputException
- mysql - 谷歌SQL副本需要上传视图的程序和功能
- mysql - woocommerce 在 Wordpress 中重复执行 mysql