L
L
Leonid Nimchenko2019-01-06 21:33:27
Apache Cordova
Leonid Nimchenko, 2019-01-06 21:33:27

How to intercept phone button press in Cordova?

Hello. I am writing an application in Cordova. What plug-in can intercept the pressing of the phone button? Now the button in the form of an arrow "Back" interests. As far as I understand, this is not possible without a Javascript plugin.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid Nimchenko, 2019-01-31
@lculver

document.addEventListener('deviceready', function() {
    var exitApp = false, intval = setInterval(function (){exitApp = false;}, 1000);
    document.addEventListener("backbutton", function (e){
        e.preventDefault();
        if (exitApp) {
            clearInterval(intval) 
            (navigator.app && navigator.app.exitApp()) || (device && device.exitApp())
        }
        else {
            exitApp = true
            history.back(1);
        } 
    }, false);
}, false);

taken from: https://lloydzhou.github.io/project/2014/04/30/pho...

K
kibez, 2019-01-17
@kibez

https://github.com/katzer/cordova-plugin-backgroun...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question