Skip to content
Advertisement

detecting a redirect with javascript – how?

Is there any way to detect whether a webpage is going to redirect me to another, knowing its URL? I mean the situation when you type URL in a text field and the script examines it for 3xx redirections.

Advertisement

Answer

Yes, you can do this quite easily in Javascript. It’d look something like:

JavaScript

Unfortunately, this only works on your own server, unless you hit a server with CORS set up. If you wanted to work uniformly across any domain, you’re going to have to do it server-side.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement