简体   繁体   中英

cordova 4 android back button error

I'm using Cordova 4.0.0 and Android 4.4.2.

Everytime Android's virtual back button is pressed, I get an error:

unimplemented WebView method onKeyDOwn called from: android.webkit.WebView.onKeyDown(WebView.java:2169)

And then it pops up an alert with jQuery unknown nodeType (I have jquery in my asset/www).

I tried to override onKeyDown in CordovaApp but it doesn't seem to do anything.

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { return false; }

I'm a little stumped why says not implemented but pops up a DOM related error. I searched everywhere can couldn't find an answer. Any help is greatly appreciated.

Try this:

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

function onBackKeyDown(ev){
    // Something
}

http://cordova.apache.org/docs/en/4.0.0/cordova_events_events.md.html#backbutton

I had similar problem, but is now resolved. Try:

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

function onBackKeyDown() {  history.go(-1); navigator.app.backHistory(); }

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