5 + app key issue process returns back button Back

Directly on the code, the official website of the example is as follows:

// H5 plus事件处理
function plusReady(){
	// Android处理返回键
	plus.key.addEventListener('backbutton',function(){
		('iOS'==plus.os.name)?plus.nativeUI.confirm('确认退出?', function(e){
			if(e.index>0){
				plus.runtime.quit();
			}
		}, 'HelloH5', ['取消','确定']):(confirm('确认退出?')&&plus.runtime.quit());
	},false);
	// 关闭启动界面
	plus.navigator.setStatusBarBackground('#D74B28');
	setTimeout(function(){
		plus.navigator.closeSplashscreen();
	},200);
}

But after using the Android side of the back button to exit the application.

ways to improve:

// H5 plus事件处理
	  function plusReady(){
	  	// Android处理返回键
		var webview = plus.webview.currentWebview();
	  	plus.key.addEventListener('backbutton',function(){
			webview.canBack(function(e) {
			    if(e.canBack) {
			        webview.back();
			    } else {
			        //webview.close(); //hide,quit
					('iOS'==plus.os.name)?plus.nativeUI.confirm('确认退出?', function(e){
						if(e.index>0){
							plus.runtime.quit();
						}
					}, 'HelloH5', ['取消','确认']):(confirm('确认退出?')&&plus.runtime.quit());		 
			    }
			})
	  	},false);
	  	// 关闭启动界面
	  	plus.navigator.setStatusBarBackground('#D74B28');
	  	setTimeout(function(){
	  		plus.navigator.closeSplashscreen();
	  	},200);
	  }

 

Published 67 original articles · won praise 24 · views 50000 +

Guess you like

Origin blog.csdn.net/u012322399/article/details/103888524