繁体   English   中英

jquery获取重定向的URL

[英]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.

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