0

I'm new to web programming. I'm working on PhoneGap android app. In that create a page from that i moving to many pages by swiping right side.

Problem: Suppose if i moved to nth page from that if i press home button, i need to clear inbetween page history and home page should get to shown.

How to do that using html or JS?

EDIT:

    function onDeviceReady() {
    document.addEventListener("backbutton", function(e) {
        e.preventDefault();
        navigator.app.exitApp();
    }, true);
}
Vignesh
  • 2,295
  • 7
  • 33
  • 41

1 Answers1

1

ok, experimental but can be a solution for you

$(document).on("pagebeforechange", function( e, data ) {
if ( typeof data.toPage === "object" ) {


                    var text = data.toPage.attr('id');

                    if(text =="your page name") {

                        $.mobile.changePage("#homepage", { transition: "none", reverse : true } );
                        e.preventDefault();

                    }
}

basically you are saying, hey, if I am coming from "your page name" don't do the default "going back" but go to home page

kangoroo
  • 359
  • 2
  • 10
  • I tried your code. Redirect to home page occur but history still is there. From home page if i press back button its gong to last opened page.... – Vignesh Sep 03 '13 at 10:23
  • Even if i add empty addEventListener for back button , in all pages back button is not working. – Vignesh Sep 03 '13 at 10:24
  • do you already have something like this for the back button? $("backbutton").live("tap",function() { if (typeof (navigator.app) !== "undefined") { clog("navigator.app.backHistory();"); if (lastAction !== "" || lastAction !== "undefined") { //lastAction(); //return; } navigator.app.backHistory(); } else { window.history.back(); } return false; }); – kangoroo Sep 03 '13 at 10:31
  • i dont have? what it ll do? //lasAction(); is commented? I used this code but getting following error "Uncaught TypeError: Object [object Object] has no method 'live' ". I'm using jquery.mobile-1.3.2.min.js and jquery-2.0.3.min.js. – Vignesh Sep 03 '13 at 10:53