简体   繁体   中英

Strange webview goBack issue in android

I am using webview in Android. But strangely, sometimes even webview canGoBack method returns true , webview goBack method doesn't work.

if (webView.canGoBack()) 
    webView.goBack();

Thanks for any idea.

I finally managed to figure out how to do it

@override
public void onFormResubmission(WebView view, Message dontResend, Message resend)
{
  resend.sendToTarget();
}

default behaviour of onFormResubmission is not to resubmit. resend.sendToTarget() changes that.

this will make your hardware back button work if you have made some code to handle the hardware button

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
  if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
    mWebView.goBack();
    return true;
  }
  return super.onKeyDown(keyCode, event);
}

I have disabled the cache and then it worked:

WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

使用这个windows.history.back();

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