Backbutton PHONEGAP

0

People help me in this one ...

I'm trying to do the backbutton function, but I tried some way and they all cause the application to quit. No emulate is already working.

I do the following:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReadyBack, false);
}

// device APIs are available
//
function onDeviceReadyBack() {
    // Register the event listener
    document.addEventListener("backbutton", onBackKeyDown, false);
}

// Handle the back button
//
function onBackKeyDown() {
    window.history.back();
    //alert("entro aqui");
}

How do I not quit the application?

    
asked by anonymous 21.12.2015 / 17:15

1 answer

0

Hello

You do not need to create a function onload. If the cord is installed correctly, try the following:

document.addEventListener("deviceready", onDeviceReadyBack, false);

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

function onBackKeyDown() {
    try {
        alert("Executou aqui!");
    }
    catch (error) {
        console.log(error);
    }
}

This is exactly how I use it in my projects. If the application still closes without executing the BackButton method, it means that there is a problem with the Cordova loading.

See if there is any error about not loading or misusing Cordova on your console and remember to declare cordova.js.

Hope it helps. :)

    
20.02.2016 / 17:24