android - How to override back button only on single page in cordova 4.0? -


i have requirement, on particular page, mean when user comes in index.html , when click button, need prompt alert saying want exit app. if says 'yes', exit else 'no'. i'm able achieve this, overriding button , checking whether user in index.html page or not shown in below code.

code sample:

function onload() {     alert("onload");     document.addeventlistener("deviceready", ondevicereay, false); }  function ondevicereay()         {                var x = document.url;             alert(x);     if( x.indexof('index') >= 0)     {             document.addeventlistener('backbutton', function(e){                       if (confirm("press button!"))                       {                      alert("you pressed ok!");                      navigator.app.exitapp();                       }                     else                       {                         alert("you pressed cancel!");                       }               }, false);         }         } 

but problem when user navigates other page , when clicks on button, it's not navigating previous page.could please shed light i'm going wrong. thank you.

put following in html page need trigger button :

document.addeventlistener("backbutton", leavepage, false);       function onpageleave(buttonindex) {          if(buttonindex==1){             window.history.back();         }         else{            }     }      function leavepage() {         navigator.notification.confirm(             'would leave  ?', // message              onpageleave,            // callback invoke index of button pressed             'leaving page request',           // title             ['yes','no']         // buttonlabels         );     } 

note you'll need notification plugin. otherwise replace simple alert().


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -