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

前端 未结 7 1271

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:29

    Thnx to StefanK comment found Here, You need to use the clearHistory() method right when the page finishes loading in the WebViewClient onPageFinished(WebView view, String url) method also in the onLoadResource(WebView view, String url) method; as follows:

        myCoolWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url){
                view.loadUrl(url);
                return true;
            }
            @Override
            public void onLoadResource(WebView view, String url) {
                // Notice Here.
                view.clearHistory();
                super.onLoadResource(view, url);
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                // And Here.
                view.clearHistory();
                super.onPageFinished(view,url);
            }
        });
    

    Also you can check the canGoBack() and copyBackForwardList() for manipulations.

    0 讨论(0)
提交回复
热议问题