javascript 如何使用 navigator.app.exitApp()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13669066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use navigator.app.exitApp()?
提问by Hodaya Shalom
I have an application built in html5 and phonegap for android, by pressing the exit button I call the following function(JavaScript):
我有一个内置的 html5 应用程序和用于 android 的 phonegap,通过按下退出按钮,我调用了以下函数(JavaScript):
function close_window() {
if (confirm("Exit?")) {
navigator.app.exitApp()
}
}
Window with the message "Exit?" appear, but the application does not close when you click OK, how can we close it?
带有“退出?”消息的窗口 出现了,但是点击确定后应用程序没有关闭,我们如何关闭它?
Is this the way to use navigator.app.exitApp()?
这是使用 navigator.app.exitApp() 的方式吗?
回答by Mayur Birari
I think your missing with call of confirm
notification.
我认为您缺少confirm
通知电话。
Please try following code, it is working fine in my app:
请尝试以下代码,它在我的应用中运行良好:
document.addEventListener("exitButton", function(){
navigator.notification.confirm(
'Do you want to quit',
onConfirmQuit,
'QUIT TITLE',
'OK,Cancel'
);
}, true);
function onConfirmQuit(button){
if(button == "1"){
navigator.app.exitApp();
}
}
回答by damo
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
checkConnection();
}
function checkConnection() {
var networkState = navigator.connection.type;
if(navigator.connection.type == Connection.NONE) {
alert("No network connection");
}
}