tags:

views:

41

answers:

1

In my JSP page, i am using

response.sendRedirect(..) to redirect to an HTML page.

Is it possible to use javascript to detect whether a redirect occurred versus a page reload?

Thanks.

+2  A: 

The easiest way I can think of to achieve this would be to put a timestamp in the query string of the redirect and read this in javascript. Set a cookie with this timestamp and detect whether it already exists to tell whether the page is being reloaded (has been loaded with the query-string before).

For how to read the query-string in javascript, see this article.

Of course, this won't work if the user has cookies disabled.

Simon Brown
Actually, the timestamp is irrelevant. The presence of the cookie alone is enough. Just let JS intercept on it and immediately delete it on page load. If the cookie is absent, then page has been reloaded.
BalusC
The timestamp is to ensure the token is unique. Also, if you want to be able to detect things correctly if they return via the link or refresh more than once, just having a cookie won't be enough.
Simon Brown