How do I disable android's device back button on some pages?
For example, once the user logs in they shouldn't be able to go back to the login page by clicking the back button on their android phone.
How do I disable android's device back button on some pages?
For example, once the user logs in they shouldn't be able to go back to the login page by clicking the back button on their android phone.
Create Javascript. Anyname u want..
Place this.
code
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.attr('dsid') == 'yourscreenName'){
e.preventDefault();
// No Action if back pressed
}
else {
//Back in History or to a Screen u specify etc..
navigator.app.backHistory()
}
}, false);
/code
Did u get your disable btn working? I added some code that might help..
Tried using the code but works partly...When i click the back button while I'm at the desired screen, the app doesn't navigate to the previous screen which is what i wanted. But I've also noticed it makes the navbar buttons to stop working when I click back 2 or 3.
Adjust the code to suit...
code
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.attr('dsid') == 'yourscreenName'){
navigator.app.backHistory()
// Goes Back if back pressed only on this screen
}
else {
//all other screens back disabled
e.preventDefault();
}
}, false);
/code
Use combinations, variations of this..
if($.mobile.activePage.attr('dsid') == 'yourscreenName' || $.mobile.activePage.attr('dsid') == 'yourscreenOtherName' ){
etc. Or !=
Any combination can be achieved..
Thanks Neil. Not working either. Breaks the other navbar links. I can't navigate to other pages.
Try history.back();
Instead of the phonegap navigator.app.backHistory()
This function is a override of the default Android action.
It cant cause errors on your nav bar.
Will work as long as placed by using Tiggzi Control Panel, Create New-- JavaScript.
GoodLuck