Start a new topic

onExit() , Avoid to close the AR on "BackButton" - Wikitude - PhoneGap

onExit() , Avoid to close the AR on "BackButton" - Wikitude - PhoneGap


I am using Wikitude SDK + PhoneGap,

I have got the icons to show on the screen, it works fine!

Now I need to avoid to blose the ARBrowser on "BackButton"...

I have added to the "HelloWorld.html" example the line below...


AR.context.onExit = function {


return false;



but this solution isn't working.


Then I have tried the phonegap solution:


adding the script ref

<script type="text/javascript" charset="utf-8" src="../www/cordova-2.0.0.js"></script> 

then the following code into the "HelloWorld.html" page

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

function onDeviceReady() {

document.addEventListener("menubutton", onMenuKeyDown, false);


function onBackKeyDown() {


            'Do You want to Close the Application?',   // message

            onConfirm,              // callback to invoke with index of button pressed

            'Close',                    // title

            'No,Yes'                   // buttonLabels


        return false;


function onConfirm(button) {

        if (button==2);



but it din't work... I have tested other PhoneGap methods  with no success..

Could you please help me to sort this?


Thank you for you help

Hi there!

You must know that PhoneGap commands are not working inside an ARchitect-HTML file.
You can add listeners in any JS inside the SampleProject's "www"-folder according PhoneGaps documentation
Whereat the "world"-folder contains all Wikitude Related components that work as documented in the "Library Reference" you can find in the ARchitect


Hi Andi,

even iuf I add this code in the event listener on the idex.html page ...

what happen then is that...

the wikitude plugin close down, and the event listener works for the index.html page.

how can I avoid this?




Hi there!

Now I understand ;-)

Please overwrite backbutton behavior of the WikitudePlugin's Android-Backbutton behavior (compare line #44 and #81 in WikitudePlugin.js for Android :


/* your very own backbutton implementation, if not set: AR view is closed */

function myBackbuttonCallback(){
// alert("user pressed back-button");


/*somewhere in your PhoneGap's JS code */

Hope that helps


Thank you Andi,

it worked fine ;)
Login or Signup to post a comment