问题描述
<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?
推荐答案
注意:如果您至少可以在重定向URL中声明变量.
在重定向到下一页之前,只需将" redir"设置为URL中的重定向页面URL(locations.href),但如下编码:
"https://www.box.com/api/oauth2/authorize?redir=" + encodeURIComponent(location.href)
现在,要获取重定向页面,您需要从当前URL获取变量" redir".检查这个问题.因此,在获得" redir"后,您将其解码:
var redirectPage = decodeURIComponent(url);
其他推荐答案
这是不可能的. JavaScript只能从其页面中获取内容
问题描述
<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 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 ?
推荐答案
NOTE: You can do that if you can at least declare variables in redirect URL.
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)
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);
其他推荐答案
That is not possible. JavaScript can only get things from its page