[英]Phonegap and Jquery mobile - Exit app with an alert
i want to exit my app with an alert of Yes or No. I currently have a script that exits the app when you are on the index side of the app. 我想以“是”或“否”的警报退出我的应用程序。当您位于应用程序的索引端时,我当前有一个脚本可以退出该应用程序。
<script language="javascript">
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#index')){
/*
Event preventDefault/stopPropagation not required as adding backbutton
listener itself override the default behaviour. Refer below PhoneGap link.
*/
//e.preventDefault();
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
</script>
Use the dialogs plugin with the confirm 将对话框插件与确认一起使用
install using the cordova CLI it if you don't have it yet: 如果尚未安装,请使用cordova CLI进行安装:
cordova plugin add org.apache.cordova.dialogs
if you use phonegap build put this on your config.xml instead: 如果使用phonegap构建,则将其放在config.xml中:
<gap:plugin name="org.apache.cordova.dialogs" version="0.2.10" />
your code 您的代码
<script language="javascript">
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#index')){
/*
Event preventDefault/stopPropagation not required as adding backbutton
listener itself override the default behaviour. Refer below PhoneGap link.
*/
//e.preventDefault();
navigator.notification.confirm(
"Do you want to exit the app?",
function (button) {
if (button==2) {
navigator.app.exitApp();
}
}
,
"EXIT",
["Cancel","OK"]
);
}
else {
navigator.app.backHistory()
}
}, false);
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.