Adam B
Adam B

Reputation: 73

MVC Ajax form and browser back button

I am currently working on an MVC site which has a search page that sits behind a login page. When the user logs in, they are redirected to the search page.

The search form uses an ajax form that returns search results to the same view.

When we have search results, the search form is no longer shown. This all works fine.

However, once you have fired off the form and have search results - the user will probably try and hit the browser back button to try and get back to the search form. Of course, this instead takes them to the previous page (the login page).

So, my question is this - I would still like to keep the form and results on the same page using ajax. Is there anyway that I can achieve this, in conjunction with when the user clicks back, it takes them to the search form?

I appreciate I am probably asking for too much here, but I thought I'd put it out there anyway!

ps - I already have a 'back to search' link which re-loads the form. I believe the average user will try and click the browser back button. I would also rather not have some sort of function on the login page that redirects them back to the search page.

Upvotes: 1

Views: 1023

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239240

You need to use the History API. It's supported in modern browsers, and there's a polyfill for IE9 and below.

UPDATE

For what it's worth, I agree with @TravisJ. This is a bad design, but if you insist on going down this path, then my notes above apply.

Upvotes: 1

Related Questions