After vue project packaged with hbuilder to APP, the return key to exit the program solution

This scheme is used in hbuilderx Lane 5 + app framework packed into the mixing App!

If you can help to you, hoping to give a thumbs up, attention!

Principle: Meaning slightly to set the system back key clicks represented by plus, at a glance.

usage:

These insert a script project index.html file head tag, the following picture carefully observed details, saying more is better to look at carefully.

The following is index.html
Here Insert Picture Description

Insert this code, the code can be copied to the following
Here Insert Picture Description

Code:

		<script>
			document.addEventListener('plusready', function() {
				var webview = plus.webview.currentWebview();
				plus.key.addEventListener('backbutton', function() {
					webview.canBack(function(e) {
						if (e.canBack) {
							webview.back();
						} else {
							//webview.close(); //hide,quit
							//plus.runtime.quit();
							//首页返回键处理
							//处理逻辑:1秒内,连续两次按返回键,则退出应用;
							var first = null;
							plus.key.addEventListener('backbutton', function() {
								//首次按键,提示‘再按一次退出应用’
								if (!first) {
									first = new Date().getTime();
									console.log('再按一次退出应用');
									setTimeout(function() {
										first = null;
									}, 1000);
								} else {
									if (new Date().getTime() - first < 1500) {
										plus.runtime.quit();
									}
								}
							}, false);
						}
					})
				});
			});
		</script>
Published 37 original articles · won praise 20 · views 6730

Guess you like

Origin blog.csdn.net/qq_39051175/article/details/99681043