该功能不起作用
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>
最佳答案
使用以下命令(我认为navigator.app
在cordova-2.2.0中不可用):
if(navigator.app){
navigator.app.exitApp();
}
else if(navigator.device){
navigator.device.exitApp();
}
关于javascript - 如何退出Android版Phonegap应用程序?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26880437/