9

I'm having trouble showing urls with redirect with an automation tool i'm using so I'm thinking of checking the url for redirects first before opening the popup.

Is it possible to get the redirect URL using javascript (no jquery or other js framework as this is not supported by the tool)?

Thanks!

1
  • What automation tool are you using? Commented Jul 28, 2012 at 4:24

1 Answer 1

10

In theory, yes. In practice, probably not.

In theory you could do an XHR head request to the URL, then check the location header to see if what you asked for is what you ended up getting. XHR will automatically follow 301/302 redirects, so there's no use checking the status code - Is it possible for XHR HEAD requests to not follow redirects (301 302)

In practice, unless the domain you're asking is your domain, or has a Access-Control-Allow-Origin header (I think it's header), the request will fail due to cross site request restrictions. HEAD XMLHttpRequest on Chromium

If you've got access to the server running your tool, you should be able to whip up a "proxy" page that issues the HEAD request, then you can XHR call your server page and it would return where the HEAD request said you'd end up.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.