问题描述
<html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
function change(){
var clientID = "hgffgh";
var clientSecret = "fgfhgfh";
var callbackUri = "https://login.live.com/oauth20_desktop.srf";
var tokenUri = "https://www.box.com/api/oauth2/token";
var authUri = "https://www.box.com/api/oauth2/authorize?"+
"client_id="+clientID+
"&response_type=code"+
"&redirect_uri="+callbackUri
//var web = window.open(authUri);
//console.log(web.location.href);
var win = window.open(authUri, "windowname1", 'width=800, height=600');
//alert(win)
}
</script>
AuthUri 打开一个新窗口.在新窗口中,当我点击允许时,我将被重定向到一个新窗口,如何获取最后一个重定向的 url?
AuthUri opens a new window. In new window when I click on allow, I will be redirected to a new window, How to get the last redirected url ?
推荐答案
注意:如果您至少可以在重定向 URL 中声明变量,您就可以做到这一点.
NOTE: You can do that if you can at least declare variables in redirect URL.
在重定向到下一页之前,只需在您的 URL 中将redir"设置为重定向页面 URL (locations.href),但编码如下:
Before you redirect to the next page, just set "redir" as the redirect page URL (locations.href) in your URL, but encoded as below:
"https://www.box.com/api/oauth2/authorize?redir=" + encodeURIComponent(location.href)
现在,要获取重定向页面,您需要从当前 URL 获取变量redir".检查这个问题.因此,在获得redir"后,您对其进行解码:
Now, to get the redirect page you need to get the variable "redir" from current URL. Check this question. So, after getting the "redir", you decode it:
var redirectPage = decodeURIComponent(url);
这篇关于如何在javascript中获取重定向的url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!