N
N
newaitix2019-06-17 23:09:07
JavaScript
newaitix, 2019-06-17 23:09:07

How to prevent backtracking on android?

I want the page to reload when I click back.
How to do it ?
Here's the version I came up with. But it seems to me that it is not stable, since the button numbers can be different.

window.onkeyup=function(ev){
      if(ev.keyCode==122){
        window.scrollTo(0,0);
        location.reload();
        ev.preventDefault();
        return false;
      }
    };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentin Khoroshilov, 2019-06-17
@horoshi10v

i use this piece of code if it is webview

webView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) { if(event.getAction() == KeyEvent.ACTION_DOWN) { WebView webView = (WebView) v; switch(keyCode) { case KeyEvent.KEYCODE_BACK: if(webView.canGoBack()) { webView.goBack(); return true; } break; } } return false; } });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question