[英]jquery get redirected url
編輯 - 沒有得到回應所以讓我問這個。 我可以這樣做嗎?
<a href="http://m.facebook.com/...." target="_webapp">facebook button</a>
讓頁面加載到當前頁面的頂部並在頁面實際重定向到jquery之前偵聽window.location.hostname?
Facebook網站網址= http://www.mysite.com
在移動應用中,您可以使用fb(YOUR_APP_ID)://授權/來請求auth_token。
使用jquery,如何在頁面進入之前捕獲重定向的URL?
即
CALLBACK_URL = fb(YOUR_APP_ID)://authorize/
url = "https://m.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=CALLBACK_URL"
WebView.navigate(url)
WebView.execture_js('$(document).ready(function() {
$("body").ajaxComplete(function(e, xhr, settings) {
if (xhr.getResponseHeader("Location").hostname == "fb(YOUR_APP_ID)://authorize/"){
alert(xhr.getResponseHeader("Location"));
// and redirect back to action in my app...
}
});
});')
如果您使用的是jQuery Mobile,請查看pagebeforeshow事件。
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/api/events.html
$('div').live('beforepageshow', function(event, ui) {
var page = $(this).attr("id");
if (page == 'mypage') {
// your logic here
}
});
您還可以嘗試在mobileinit事件的處理程序中添加注冊ajaxComplete處理程序。
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/api/globalconfig.html
$(document).bind("mobileinit", function() {
$("body").ajaxComplete(function(e, xhr, settings) {
if (xhr.getResponseHeader("Location").hostname == "fb(YOUR_APP_ID)://authorize/"){
alert(xhr.getResponseHeader("Location"));
// and redirect back to action in my app...
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.