DrLove
DrLove

Reputation: 51

JS - How to get URL of redirect

Hi I'm trying to find a way to get the URL of a redirected webpage.

Ex/ I type in a url to my web browser, "http:foo.com", and it redirects me to "http://foo.com/bar".

How can I use fetch or something else to have "http://foo.com/bar" returned to me? (The website I'm trying to receive the url from "has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Please and thanks in advance for ideas / solutions.

Upvotes: 3

Views: 6977

Answers (1)

Quentin
Quentin

Reputation: 943615

You can't. XMLHttpRequest and fetch silently follow redirects, and no information about the final URL is available in the object afterwards.

Even if that information was available, the Same Origin Policy would prevent you from accessing it (as the error message indicates).


Use a server side technology instead.

Upvotes: 1

Related Questions