Problem description: Hbuilder packaging when the return key click mobile app, the app will be directly exit and return to the previous page.
Write in public js file, each page are introduced the js, HTML code is as follows:
Document. The addEventListener (' plusready ', function () {
Var webview=plus. Webview. CurrentWebview ();
Plus. Key. AddEventListener (' backbutton ', function () {
Webview. CanBack (function (e) {
If (e.c. with our fabrication: anBack) {
Webview. Back ();
} else {
Webview. Close ();//hide, quit press directly to exit the APP phone back
//plus. Runtime. The quit ();
}
})
});
});
The above a piece of code can be realized with the phone when the return key to return to previous page, when to return to the home page, and then press can exit the APP, mobile phone back the following code can not
Click on the cell phone return key exit two tips, the code is as follows:
Note: in the hbuilder new mobile App, choose a template - mui project, in the page introducing mui. Js and mui. Min. The effect of js, click twice to exit the program will happen
Mui. PlusReady (function () {
//return key processing home page
//processing logic: 1 seconds, press the return key twice in a row, exit the application;
Var first=null;
Plus. Key. AddEventListener (' backbutton ', function () {
//button for the first time, prompt 'then exit the application once
if (! First) {
The first=new Date (). GetTime ();
Mui. Toast (' then exit the application once ');
SetTimeout (function () {
first=null;
}, 1000);
} else {
If (new Date (). GetTime () - first & lt; 1000) {
Plus. Runtime. The quit ();
}
}
}, false);
});
According to mobile phones return key to return to previous page + click back button twice exit prompt effect, complete js code:
Note: this code when on the front page, press the phone back without effect, will not quit the APP, have to click twice
<script>
Document. The addEventListener (' plusready ', function () {
Var webview=plus. Webview. CurrentWebview ();
Plus. Key. AddEventListener (' backbutton ', function () {
Webview. CanBack (function (e) {
If (e.c. with our fabrication: anBack) {
Webview. Back ();
} else {
//webview. Close ();//hide, quit
//plus. Runtime. The quit ();
Mui. PlusReady (function () {
//return key processing home page
//processing logic: 1 seconds, press the return key twice in a row, exit the application;
Var first=null;
Plus. Key. AddEventListener (' backbutton ', function () {
//button for the first time, prompt 'then exit the application once
if (! First) {
The first=new Date (). GetTime ();
Mui. Toast (' then exit the application once ');
SetTimeout (function () {
first=null;
}, 1000);
} else {
If (new Date (). GetTime () - first & lt; 1500) {
Plus. Runtime. The quit ();
}
}
}, false);
});
}
})
});
});
</script>
Reprinted from: https://www.cnblogs.com/zyl-930826/p/9212779.html