简体   繁体   中英

How to capture android back key/button press on a web app (only JavaScript, HTML5/CSS, no Java)?

The following code works okay, when you open in android/android-chrome browser.

window.onbeforeunload = function() {return "Confirm your actions before exiting."; }

But, when you save the app to the android home-screen as a web app, and then app runs in full screen mode, this has no effect.

Is there any alternative for WebApp mode? Any way to capture the back button press via HTML5 or Javascript APIs ?

如果您使用cordova / phonegap,请尝试此操作

document.addEventListener("backbutton", this.onBackKeyDown, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM