[英]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 打開一個新窗口。 在新窗口中,當我單擊允許時,我將被重定向到一個新窗口,如何獲取最后一個重定向的 url ?
注意:如果您至少可以在重定向 URL 中聲明變量,您就可以做到這一點。
在您重定向到下一頁之前,只需在您的 URL 中將“redir”設置為重定向頁面 URL (locations.href),但編碼如下:
"https://www.box.com/api/oauth2/authorize?redir=" + encodeURIComponent(location.href)
現在,要獲取重定向頁面,您需要從當前 URL 獲取變量“redir”。 檢查這個問題。 因此,在獲得“redir”后,您將其解碼:
var redirectPage = decodeURIComponent(url);
那是不可能的。 JavaScript 只能從它的頁面獲取東西
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.