开发者

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 origi开发者_高级运维nal 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.


I used the clearView() method, however I'm now having issues that when I loadData() right after it, it doesn't seem to load the data.


What about loadUrl("about:blank"), and then clearHistory()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜