Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Disable Android's device back button on some pages.

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.

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Disable Android's device back button on some pages.

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

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Disable Android's device back button on some pages.

Did u get your disable btn working? I added some code that might help..

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Disable Android's device back button on some pages.

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.

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Disable Android's device back button on some pages.

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..

Kevin
Posts: 0
Joined: Sun Oct 07, 2012 7:58 pm

Disable Android's device back button on some pages.

Thanks Neil. Not working either. Breaks the other navbar links. I can't navigate to other pages.

Emmz
Posts: 0
Joined: Sat Jun 23, 2012 11:06 pm

Disable Android's device back button on some 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

Return to “Issues”