我如何退出Phonegap应用程序的Android?

时间:2014-11-12 06:12:14

标签: javascript android cordova

此功能无效

navigator.app.exitApp();

执行上线错误信息时

[INFO:CONSOLE(984)] "Uncaught TypeError: Object [object Object] has no method 'exec'", source: file:///android_asset/www/cordova-2.2.0.js (984).


<!DOCTYPE HTML>
<html>
    <head>
        <title>PhoneGap</title>

        <script type="text/javascript" src="cordova-2.2.0.js"></script>    
        <script type="text/javascript" charset="utf-8">
            function onLoad()
            {
                document.addEventListener("deviceready", onDeviceReady, true);
            }
              function onDeviceReady() {
                document.addEventListener('backbutton', exitFromApp, false);
            }
            function exitFromApp()
            {
                if(navigator.app)
                {
                    navigator.app.exitApp();
                }
                else if(navigator.device)
                {
                    navigator.device.exitApp();
                }
            }
        </script>
    </head>

    <body onload="onLoad();">
        <button name="buttonClick" onclick="exitFromApp()">Click Me!</button>
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

使用以下(我认为{/ 1}}在cordova-2.2.0中不可用):

navigator.app