1
<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 ?

Ed Lucas
  • 5,955
  • 4
  • 30
  • 42
Anirudh Holla
  • 11
  • 1
  • 1
  • 3

2 Answers2

1

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);
Community
  • 1
  • 1
  • 1
    OP doesn't have any control over third party server or access to page code – charlietfl Jun 02 '16 at 23:05
  • @charlietfl How so? There's no code to access. He'll have to parse the URL to get the redirect page. –  Jun 02 '16 at 23:07
  • When clicks on `approve` a new url is loaded in window... that server isn't going to use your `redir` – charlietfl Jun 02 '16 at 23:09
  • @charlietfl Exactly. The "redir" will continue in the page URL and can be parsed in JavaScript. –  Jun 02 '16 at 23:13
  • 1
    No it won't continue. When the form in that window submits the other server determines the new location. It's that new location that OP wants for some reason – charlietfl Jun 02 '16 at 23:15
  • @charlietfl I see. Anyway, I'll let the answer available if he changes his idea one day or one century. –  Jun 02 '16 at 23:19
-5

That is not possible. JavaScript can only get things from its page

FlappyBoy
  • 3
  • 1