2

Okay, I'm making app with phonegap, and in the app I have a home button which goes to the home screen of the app, but if I click the back key after I touched the home button it goes to the page I was on before I clicked the home button, is it possible to reset the history when you navigate to the homepage? Thanks :)

William Lewis
  • 536
  • 1
  • 8
  • 26

3 Answers3

4

You can't clear the history. You can listen for back button event:

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
    // Handle the back button
}

and stop the propagation.

Flatlineato
  • 1,066
  • 15
  • 32
0

The link below recommends using location.replace(url) instead of replacing the history completely, which I'm not sure is possible anyway. However, given that this is a constrained environment (an app) wiping the history might make sense - again, if possible if you're in an app.

Clear browser history

Alternatively, couldn't you just remove the back key and replace it with a custom one?

Community
  • 1
  • 1
Joshua
  • 3,615
  • 1
  • 26
  • 32
0

inside the event handler of the button which takes you to home:

startActivity(activityForHome); //I guess you already have this line
finish();  //now add this line
Sarwar Erfan
  • 18,034
  • 5
  • 46
  • 57