如何在JavaScript中获取重定向的URL [英] How to get the redirected url in javascript

查看:1129
本文介绍了如何在JavaScript中获取重定向的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆