2

I'm not even sure how to search for this one or if this is the right place to ask so I'm sorry if not.

I have inherited a HUGE jQuery driven ASP.NET site. Everything is loaded via jQuery and it's all loaded into the same page.

There are currently no back buttons and justifiably the client has now asked for a "back button" on each "page" so they can skip back to the previous "pages".

Problem is, there aren't actual pages, it's different scripts that have been run to populate different information on the same page.

What is the easiest way of handling this? So far I am assigning the previous query to the back button every time a "page" loads so they can go back once, but how can I allow them to click back twice or more? (as if using the browser back button?)

Bex
  • 4,898
  • 11
  • 50
  • 87
  • 1
    Create a cookie that holds an array of previously visited 'pages.' When the user presses back you check the cookie and call the given query associated with the page. When you go back, just pop the last page out of the array. – Wild Beard Feb 04 '15 at 14:57
  • I agree with @Press. Store a cookie per page. Or if you want to you can store each "page path" in a JSON object, since the page never reload. – Max Baldwin Feb 04 '15 at 14:58
  • 1
    Use a URL hash to maintain state: http://stackoverflow.com/questions/4113397/working-with-single-page-websites-and-maintaining-state-using-a-url-hash-and-jqu – Diodeus - James MacFarlane Feb 04 '15 at 14:59
  • There are plugins and libraries which will help you with that. http://stackoverflow.com/questions/4347168/jquery-history-plugin – Andy Feb 04 '15 at 15:00
  • You should probably take a look at a routing library designed specifically to handle history. It will allow you to dynamically update the URL and run arbitrary bits of code in the process... which is what you need. http://visionmedia.github.io/page.js/ – Josh Feb 04 '15 at 15:01
  • Use the "I ain't gonna clean another one's rubbish"-tactic. Just explain your boss the site is not maintainable, this would need a total structural deep-down rewrite of code, so a new website will be faster then implementing a back button. All this is partially true btw, so you only would have to lie a little bit – giorgio Feb 04 '15 at 15:01
  • [pushState]( https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history) seems like a good place to start. – badcook Feb 04 '15 at 15:06

0 Answers0