0

I need to know the current URL from PebbleKit Javascript, my code is like follows:

Pebble.addEventListener("ready",
    function(e) {
        console.log("JS Ready");

        var req = new XMLHttpRequest();
                req.open('GET', URL_MAIN, true);
                req.onload = function(e) {
                        console.log("Status returned: " + req.status); // status is 404
                        console.log(window.location.href);
                        console.log(location);
                        console.log(window.location.host);
                        console.log(document.URL);
                        console.log(document.baseURI);
                        console.log(window.location);
                        console.log(JSON.stringify(Pebble)); // returns {}
                        //var response = JSON.parse(req.responseText);
                        //console.log
                        //console.log(response.redirectUrl);
                        console.log(req.redirectUrl);
                        console.log(req.getResponseHeader('Location')); // This returns null
                        console.log(JSON.stringify(e)); // Nothing about the url

        }
        req.send(null);
    }
);

I tried some tests but no one returned me the current url. window.location.href and others returns this:

pebble-js-app.js:13 file:///android_asset/jskit_startup.html?params=%7B%22loadUrl%22%3A%22file%3A%5C%2F%5C%2F%5C%2Fdata%5C%2Fdata%5C%2Fcom.getpebble.android%5C%2Fapp_jskit_installed_apps%5C%2FTelepizza__1%5C%2Fpebble-js-app.js%22%7D

The use case is this:

  1. I need to open the first URL (that has a 302 redirect).
  2. Later, with this URL I can starting to make requests.

There is some way to get the current URL from Pebble Javascript?

antonio
  • 540
  • 1
  • 5
  • 19
  • 1
    What would the URL be in this context? The JS file is running on the user's phone, so the value returned from window.location.href is the URL of that file. – matthewtole Aug 01 '14 at 13:23

1 Answers1

0

Did you check req.responseURL field? I should contain the URL of requested page.

Also you can check answers to jQuery and AJAX response header if server responds with a redirect.

Community
  • 1
  • 1
dmitrijs
  • 73
  • 5