2

I want to get the redirected URL of a source. Example, this URL:

https://www.novelupdates.com/extnu/2633428/

Redirects to this URL:

http://www.tapread.com/book/index?bookId=91&chapterId=10725

So I want to get the redirected URL (http://www.tapread.com/book/index?bookId=91&chapterId=10725 one).

How can I do this via jQuery so the client (not server) gets the redirected URL?

EDIT:

So I need a function:

get_redirect_url('https://www.novelupdates.com/extnu/2633428/');

Which would return:

http://www.tapread.com/book/index?bookId=91&chapterId=10725
Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155
  • `if( window.location.href === FROM ) { window.location.href = NEW_URL }` – darklightcode Jun 13 '19 at 14:56
  • @HereticMonkey I want to get the **redirected** URL. So in my example above, I should be: `http://www.tapread.com/book/index?bookId=91&chapterId=10725` – Henrik Petterson Jun 13 '19 at 15:03
  • Wouldn't that just be the current URL? – Heretic Monkey Jun 13 '19 at 15:04
  • 2
    @HereticMonkey Please see my latest edit which should explain it. – Henrik Petterson Jun 13 '19 at 15:04
  • Ah, you want to get the result of the redirect. Sounds more like [Capture redirect location of javascript XMLHttpRequest](https://stackoverflow.com/q/4465547/215552) then. – Heretic Monkey Jun 13 '19 at 15:08
  • 1
    You'd need to do this server side and check the response header for a 301 and the response domain. You can't do this client-side as the domain you've shown in the example doesn't have CORS headers in the response. – Rory McCrossan Jun 13 '19 at 15:09
  • 1
    @RoryMcCrossan Is there no *wild* workarounds, like loading the URL into a iframe and then after some time, *getting* the redirected URL? You get the idea... – Henrik Petterson Jun 13 '19 at 15:10
  • No, you can't interact with a cross-domain iframe like that. You could do it using `postMessage()`, but this would rely on the third party actually writing the code to tell you the new domain. This seems massively unlikely. – Rory McCrossan Jun 13 '19 at 15:19
  • Possible duplicate of [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – ℛɑƒæĿᴿᴹᴿ Jun 13 '19 at 17:54
  • 1
    @ℛɑƒæĿ No, they're trying to get the URL that another site redirects to. They are not trying to perform the redirect. – Austin Mullins Jun 13 '19 at 17:56
  • I don't think this is possible, based on this answer: https://stackoverflow.com/a/8241461/1896761 – Austin Mullins Jun 13 '19 at 18:14

0 Answers0