如何使用navigator.app.exitApp()?

5

我有一个基于HTML5和PhoneGap的Android应用程序,通过按退出按钮,我调用以下函数(JavaScript):

function close_window() {
    if (confirm("Exit?")) {
        navigator.app.exitApp()
    }
}

当你点击"退出"时,出现了一个带有"退出?"消息的窗口,但是应用程序并没有关闭,我们该如何关闭它呢?

使用navigator.app.exitApp()这个方法是可以实现的吗?

2个回答

10

我认为你在调用 confirm 通知时出现了错误。

请尝试以下代码,在我的应用程序中它可以正常工作:

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(); 
    }
}

0

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");
}
}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接