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

前端 未结 7 1284

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

    use mweb.clearView(); before loading the new URL.

    Edit:

    clearView() was deprecated in API level 18. Use WebView.loadUrl("about:blank") to reliably reset the view state and release page resources (including any running JavaScript).

    to solve the issue raised by @Liang:

    To have a consistent back navigation, you can override "onPageFinished", and inside it check whether the url contains "about:blank" or not. if yes, use "webview.goBack()"

提交回复
热议问题