简体   繁体   English

如何在javascript中获取重定向的url

[英]How to get the redirected url in 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. AuthUri 打开一个新窗口。 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 中声明变量,您就可以做到这一点。


Before you redirect to the next page, just set "redir" as the redirect page URL (locations.href) in your URL, but encoded as below:在您重定向到下一页之前,只需在您的 URL 中将“redir”设置为重定向页面 URL (locations.href),但编码如下:

"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.现在,要获取重定向页面,您需要从当前 URL 获取变量“redir”。 Check this question .检查这个问题 So, after getting the "redir", you decode it:因此,在获得“redir”后,您将其解码:

var redirectPage = decodeURIComponent(url);

That is not possible.那是不可能的。 JavaScript can only get things from its page JavaScript 只能从它的页面获取东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM