3

I have used following code to exit from application. For first time it works perfectly. But when I opened some next screens and then came back to screen where I wanted to close my application, it fails to close application.

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">

function onLoad() 
    {
        document.addEventListener("deviceready", onDeviceReady, false);
        //alert("Load");
    }

    function onDeviceReady() 
    {
        document.addEventListener("backbutton", onBackKeyDown, true);
       // alert("Device Ready");
    }


    function onBackKeyDown() 
    {
        navigator.app.exitApp();        
    }
</script>

Please suggest something which will work ....

Madhuri
  • 158
  • 1
  • 8

1 Answers1

0

You should delete navigation history on page load so whenever you press the back button it will exit the app automatically.

        if (typeof navigator.app !== 'undefined') {
            navigator.app.clearHistory();
        }

Above code will work. Since navigator.app is undefined for iOS, this will work cross platform.

prabhat
  • 620
  • 5
  • 18