简体   繁体   English

jquery获取重定向的URL

[英]jquery get redirected url

Edit - Wasn't getting a response so let me ask this. 编辑 - 没有得到回应所以让我问这个。 Can I do this? 我可以这样做吗?

<a href="http://m.facebook.com/...." target="_webapp">facebook button</a>

Let the page load on top of the current page and listen for the window.location.hostname before the page actually redirects with jquery? 让页面加载到当前页面的顶部并在页面实际重定向到jquery之前侦听window.location.hostname?


Facebook site url = http://www.mysite.com Facebook网站网址= http://www.mysite.com

In a mobile app, you can use fb(YOUR_APP_ID)://authorize/ to request for auth_token. 在移动应用中,您可以使用fb(YOUR_APP_ID)://授权/来请求auth_token。

Using jquery, how can I catch the redirected url before the page goes to it? 使用jquery,如何在页面进入之前捕获重定向的URL?

ie

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...
        }
    });
});')

If you are using jQuery Mobile, take a look at the pagebeforeshow event. 如果您使用的是jQuery Mobile,请查看pagebeforeshow事件。

http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/api/events.html 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
    }
});

You might also try adding registering an ajaxComplete handler within a handler for the mobileinit event. 您还可以尝试在mobileinit事件的处理程序中添加注册ajaxComplete处理程序。

http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/api/globalconfig.html 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