Backbutton PHONEGAP

Asked

Viewed 172 times

0

Help me with this one...

I’m willing to do the job of backbutton, however I have tried some form and all make the application come out. emulate already working.

I’ll tell you what:

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 to stay in the app ?

  • take a look at this and see if it helps you http://pt.androids.help/q3977

  • You didn’t even help me. I’m struggling to get this.

1 answer

0

Hello!

You do not need to create an onload Function. If Cordova 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 even then the application closes without running the Backbutton method, it means that there is some problem with loading Cordova.

See if there is an error about not loading or loading Cordova incorrectly on your console and remember to declare Cordova.js.

I hope it helps. :)

  • Actually my problem was because I used the Framework and it was managing it, when I located I solved my problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.