3

I'm having a bit of a problem here. I'm making a cordova app, which has a navigation menu. If the user navigates like this:

-> page one -> page two -> page one

there will be 2 pages in the history, including an instance of the page one (which is the same the user is seeing right now). If the user goes back, it will be like

| page one | -> page two -> page one

So, if the user pressed back on the page one, he certainly doesn't want to see it again while going out of the app, so I want to remove it from the stack.

Note that i'm not trying to remove the previous page from the history, what I want is to remove all instances of the page I am visiting from the navigation stack.

I hope I explained good enough. How can this be achieved?

seugnimod
  • 64
  • 1
  • 9
  • 1
    What you can do is to override the android back button. When he presses it, you can inspect the url and if the user is on page 1 you can force the app to close. Take a look here: http://docs.phonegap.com/en/1.7.0/cordova_events_events.md.html#backbutton – jpgrassi Apr 28 '14 at 14:44
  • Yes, I was going to make that, and thank you for reminding me, but maybe I didn't explain right. If I have a history like -> page one -> page two -> page three -> page two When I go the 2nd time to the page two, I want to remove the first instance from the history, so the user doesn't see it again. – seugnimod Apr 29 '14 at 10:58
  • Are you using any framework like angularJS to build your app? Also you might want to take a look at push and replace states: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history – jpgrassi Apr 29 '14 at 14:46
  • I am using cordova AKA phonegap, but not angularJS. I have already looked at that link but concluded that using window.history.go(-3) (for example), would take a lot of work because I would have to increment some values, everytime I navigate to a new page, so I would be capable to go to the previous instance, instead of opening a new one. Maybe I'm missing something... Thanks a lot ;) – seugnimod Apr 30 '14 at 09:17

0 Answers0