How to clear WebView content?

I have a WebView in my app with wrap_content width and height

Before I use webview.loadData, the width and height of the it was 0, after I load a page (or I use webview.loadData) , it'll display a web page.

My question is , how can I clear the webview to recover it back to the original state, just as before it loadData?


I found this answer, pretty helpful: How do I clear a WebView's content before loading a page?

It is for Cocoa, but basically just call:

webView.loadUrl("about:blank")

The only complete solution is to check for SDK version.

if (Build.VERSION.SDK_INT < 18) {
   webView.clearView();
} else {
   webView.loadUrl("about:blank");
}

use following statement before loadData:

view.loadUrl("javascript:document.open();document.close();");

WebView.clearView();

This will clear the view from the webview.