【发布时间】:2015-10-13 04:33:12
【问题描述】:
我正在尝试使用以下方法通过硬件后退按钮阻止返回上一页:
$ionicPlatform.onHardwareBackButton(function () {
if($state.$current.name=="authentication") {
$ionicPopup.confirm({
title: 'System warning',
template: 'Are you sure you want to exit?'
}).then(function(res){
if( res ){
navigator.app.exitApp();
}
})
}
});
但它不起作用。当警报弹出框出现时,它仍然返回到上一页。
我怎样才能阻止它?
【问题讨论】:
-
我想我对this question的回答可以帮助到你。
-
@AndreKreienbring 感谢您的评论。但我想要的是防止它返回上一页,也不要在某些页面上退出应用程序。
-
这应该完全可以通过我发布的代码来实现,因为您可以决定如何对 backButtonAction 做出反应。通过删除此行
navigator.app.backHistory();您可以防止应用程序返回历史记录。当然,你也可以对任何你喜欢的 $state 这样做。 -
@AndreKreienbring 不管有没有
navigator.app.backHistory();,问题还是会回到上一页。 -
你可以试试这个 .run(function($ionicPlatform, $ionicPopup) { // 禁用主页上的 BACK 按钮 $ionicPlatform.registerBackButtonAction(function(event) { if (true) { // 你的检查这里 $ionicPopup.confirm({ title: '系统警告', template: '你确定要退出吗?' }).then(function(res) { if (res) { ionic.Platform.exitApp(); } }) } }, 100); });