Page 1 of 1

Disable Android's device back button on some pages.

Posted: Sat Oct 20, 2012 9:15 am
by Kevin

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.


Disable Android's device back button on some pages.

Posted: Sat Oct 20, 2012 12:18 pm
by Emmz

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


Disable Android's device back button on some pages.

Posted: Sat Oct 20, 2012 12:21 pm
by Emmz

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


Disable Android's device back button on some pages.

Posted: Sat Oct 20, 2012 1:14 pm
by Kevin

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.


Disable Android's device back button on some pages.

Posted: Sat Oct 20, 2012 1:39 pm
by Emmz

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


Disable Android's device back button on some pages.

Posted: Sun Oct 21, 2012 7:37 am
by Kevin

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


Disable Android's device back button on some pages.

Posted: Sun Oct 21, 2012 1:34 pm
by Emmz

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