How do I clear previous WebView's content before loading the next WebView?

前端 未结 7 1282

My scenario is initially I am loading a WebView and later on I am loading the same WebView with a different URL.

My problem is whenever I am loading the next URL I c

7条回答
  •  我在风中等你
    2020-12-15 18:13

    I guess you can use Webview.clearHistory(). But remember so impotent to call this after WebView is loaded. For example the code:

    webView.loadData(someUrl);
    webView.clearHistory();
    

    won't work because webView is not loaded. We have to clear it like:

    webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    clearHistory();
                }
    }
    

提交回复
热议问题