To realize the listening of the primary physical return key:
var exitAppTicker = 0; document.addEventListener("deviceready",function(){ document.addEventListener("backbutton", function(){ var pageUrl = window.location.href; var n = pageUrl.lastIndexOf('? '); var m = pageUrl.lastIndexOf('/'); var str = '' if (n > 0) { str = pageUrl.substring(m+1,n); // get PageName} else {STR = PageUrl.substring (m+1); / / get pageName} the if (STR = = 'index' | | STR = = '| | STR = =' loginPhone ') {if (exitAppTicker = = 0) {exitAppTicker++; SetTimeout (function(){exitAppTicker = 0; }, 2000); }else if(exitAppTicker == 1){ navigator.app.exitApp(); } }else{ history.back(); } }, false); },false);
Custom Toast, JS to achieve the android Toast effect
/** * Custom Toast, * @param MSG * @param duration */ function showToast(MSG, MSG, MSG) duration) { duration = isNaN(duration) ? 2000 : duration; var m = document.createElement('div'); m.innerHTML = msg; m.style.cssText = "width:60%; min-width:150px; background:#000; Opacity: 0.5; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:5px; position:fixed; top:70%; left:20%; z-index:999999; font-weight:bold;" ; document.body.appendChild(m); SetTimeout (function() {var d = 0; m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in'; m.style.opacity = '0'; setTimeout(function() { document.body.removeChild(m) }, d * 1000); }, duration); }