0

i am developing one website in which main content is getting load by jquery ajax according to selected menu item.

on selecting any menu item, url get changed according to this pattern:

http://host/domain/index.php?pageid=page

here page refers to the page that i want to load into main content using ajax.

now in this case, i want to reload the previous page if user clicks on back button of browser.

can anyone help me out how could i achieve this?

Kalpana Dixit
  • 449
  • 3
  • 7
  • 19
  • How do you change that url? using built in history.pushState or there is some plugin? – Viktor S. May 16 '13 at 12:27
  • URL actually changes in browser? If not, then I doubt you can do anything. The bad point in AJAX is that you can't go back, because you didn't change page literally. – JorgeeFG May 16 '13 at 12:31
  • @FAngel: nope...i am not using history. whenever user will click on menu item, using a href i am calling url in which i am passing page parameter in query string, then i am fetching this parameter and based of parameter calling the particular page – Kalpana Dixit May 16 '13 at 12:36

1 Answers1

0

If you do not change a url, then I'm afraid that is not possible.

Suppose you should better try to use window.history which provides onpopstate event when user clicks back button. But you will need to modify url in browser with history.pushState/history.replaceState functions. Possibly, you can add same url to history, so it will not be changed visually. And then take previous URL from your custom history array. But not sure if popstate will work if you place same url with pushState

But that will work in modern browsers only. To make it work in all browsers, you should better use some history plugin (for example this) which will also handle IE using hashtags

Viktor S.
  • 12,736
  • 1
  • 27
  • 52