简体   繁体   中英

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?


Facebook site url = http://www.mysite.com

In a mobile app, you can use fb(YOUR_APP_ID)://authorize/ to request for auth_token.

Using jquery, how can I catch the redirected url before the page goes to it?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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