Search code examples
javascriptjqueryjquery-mobilebrowser-history

use of history back button dettection


I'm making jquery mobile app and have one problem. I have three pages:

  • main page with category clicks
  • page with itemlist and category filter.
  • page with item details

when I click category on main page I go to second page with modified select button and filtered list. after clicking item and using history button everything is ok - right category is selected. Problem is when I want to on a second page change category. After clicking item and going back in history I go back to first category not previously changed one. Is there a way to detect wheather back button was used??


Solution

  • $(window).on("navigate", function (event, data) {
      var direction = data.state.direction;
      if (direction == 'back') {
        // do something
        localStorage.back=1;
      }
    });
    

    did the trick.