Ionic 实现双击返回键退出功能
Ionic 实现双击返回键退出功能
本文转自http://ionichina.com/topic/5514b539b6421f9166aa5f88,非常感谢 zxj963577494的分享,为方便自己日后查阅,特记录。
一、准备 Toast插件 插件地址:cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git 二:代码
.run(function($ionicPlatform, $rootScope, $location, $timeout, $ionicHistory, $cordovaToast){ $ionicPlatform.ready(function($rootScope){// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard// for form inputs)if(window.cordova && window.cordova.plugins.Keyboard){ cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);}if(window.StatusBar){// org.apache.cordova.statusbar requiredStatusBar.styleDefault();}});//双击退出 $ionicPlatform.registerBackButtonAction(function(e){//判断处于哪个页面时双击退出if($location.path()=='/tab/news'){if($rootScope.backButtonPressedOnceToExit){ ionic.Platform.exitApp();}else{ $rootScope.backButtonPressedOnceToExit =true; $cordovaToast.showShortTop('再按一次退出系统'); setTimeout(function(){ $rootScope.backButtonPressedOnceToExit =false;},2000);}}elseif($ionicHistory.backView()){ $ionicHistory.goBack();}else{ $rootScope.backButtonPressedOnceToExit =true; $cordovaToast.showShortTop('再按一次退出系统'); setTimeout(function(){ $rootScope.backButtonPressedOnceToExit =false;},2000);} e.preventDefault();returnfalse;},101);})
相关推荐
绿豆饼 2020-07-28
kfq00 2020-04-10
shichong 2015-05-14
samllcat 2019-07-01
Android进阶 2019-07-01
liujia 2019-07-01
MonkeyKingBi 2019-06-29
wangdazhu0 2019-06-28
liujia 2019-06-28
芯果科技蔡彦 2016-08-25
半纸药笺 2020-07-26
半纸药笺 2020-06-14
芯果科技蔡彦 2020-04-30
芯果科技蔡彦 2020-04-14
samllcat 2020-03-27
ZillahV0 2016-08-27
半纸药笺 2019-11-18
qixiang0 2015-04-24