1

I want to disable the android back button click in my web app which I built using html5, javascript and jquery mobile.

On clicking the android back button, it minimizes my web app. Web app goes to the background. How can i prevent this ? I tried so many ways like,

document.addEventListener('backbutton', function(){});  

data- backbtn = false etc... but still no luck..

If it was a native android application , it is easy. But how to do this is in a web app.

Appreciate any kind of help.

3 Answers 3

2

Are you working in Phonegap?

//Deviceready function
document.addEventListener('deviceready', function() {

    document.addEventListener("backbutton", goBack, false);

}, false);


//Function for back button function
function goBack(){
}
Sign up to request clarification or add additional context in comments.

1 Comment

No.. I am not using phone gap.. Just using eclipse ide with html5 and javascript.
1

put the following code inside your Main Activity .java class

@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {

            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

4 Comments

I dont have a mainactivity here. This is not a native app. It is a web app developed using javascript and html5.
in your src folder, there should be one .java class
No.. this is web app which runs in browser. There is no java file as such
If it does not have a proper wrapper(java class/app) you could use some code to see what keys are presed. Keycode appended in one div, to see the code of back button. and return false when that specific keycode is sent to body / document
0

If i understand you right a web app is basically opening a web page in a browser on your phone.You cannot disable the back key from a web app.

It is built into the phone to put applications(in this case the browser) into the background when the back key is pressed.

If you wish to use native features while writing your code in html/css/javascript, then checkout a wrapper like Phonegap. It easily packages your web app into a native app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.