The configuration file
1. Create a folder under the project: commonFunction-> PhysicbackListener.js
Edit the code
2. Copy code in this js file:
var webview = plus.webview.currentWebview(); plus.key.addEventListener('backbutton', function () { webview.canBack(function (e) { if(e.canBack){ webview.back(-1); }else{webview.close(); // Close application}})}); })Copy the code
Introduced the global
3. Global import listener, main.js:
import physicBackListener from '.. / commonFunction physicBackListener '/ / physical return key Vue. Prototype. PhysicBackListener = physicBackListenerCopy the code
If the real machine does not return normally after packaging, or there is a logic problem or closed after returning to open the route is not configured
Method 2: The first step is to create the js file folder to be referenced in main
The JS text content is as follows
/ / to monitor mobile physical document. The return key events addEventListener (' plusready ', function () {var first = null; plus.key.addEventListener('backbutton', function() { if(! first) { first = new Date().getTime(); Var urls = location.hash.split('/')[1] //var Currenturls = location.hash.split('/')[0] if (urls=="NewD"||urls=="StartScan") { // alert(urls); //history.go(-1); plus.runtime.quit(); App}else{history.back(-1); } setTimeout(function() {first = null; }, 500); } else {if(new Date().gettime () -first < 500) {plus.runtime.quit(); // Exit app}}}); })Copy the code