1

My html page redirects to a different URL. I want to handle this somehow and catch the new URL, which my page is redirecting to. Is it possible through JavaScript?

EDIT:

The redirected URL is out of my domain. What I want to do is to catch the URL and make a request to the URL myself.

EDIT2:

It is not my code that is doing the redirection. It is done through some kind of third party applet.

1
  • var str = window.location.href; alert(str); This javascript code will give you the URL of any page in which this code is placed. So you might use that in your new page to get the URL if thats what you want. Else please explain in detail. Commented Aug 9, 2012 at 5:24

1 Answer 1

2

You cannot intercept the setting of URLs to other pages in other domains. At the point the URL is set to the new page, the new page is already loading and your javascript is no longer present.

If it is your own code in your own page doing the redirecting, then you will just need to rewrite that code to do what you want. Create a function for redirecting, change all places that redirect to use that function and in that function do whatever work you want to do BEFORE you set window.location to the new URL.

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

1 Comment

If it's code you can't change that is redirecting, then there is nothing you can do about it. You can investigate window.onbeforeunload, but it's probably not exactly what you want.

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.