.run(function($ionicPlatform, $location, $rootScope, $timeout, $cordovaToast, $ionicHistory) { //please install cordova and cordovaToast $ionicPlatform.registerBackButtonAction((function(e) { /* Your back button action will override each of the above actions whose priority is less than the priority you provide. For example, an action assigned a priority of 101 will override the ‘return to previous view’ action, but not any of the other actions. */ //ionic.Platform.exitApp(); /** * 判断是否为需要双击退出页面 * @returns {boolean} */ function isRootPage(){ //判断处于哪个页面时双击退出 var arr = $location.path().split("/"); if(arr.length <= 3){ return true; } return false; } if(isRootPage()){ if ($rootScope.backButtonPressedOnceToExit) { ionic.Platform.exitApp(); } else { $rootScope.backButtonPressedOnceToExit = true; $cordovaToast.showShortTop(‘再次点击退出应用‘); setTimeout(function () { $rootScope.backButtonPressedOnceToExit = false; }, 2000); } }else{ $ionicHistory.goBack(); } //e.preventDefault(); }), 101); })
原文:http://www.cnblogs.com/map90/p/4923530.html