How to clear WebView content?

前端 未结 6 732
滥情空心
滥情空心 2020-12-24 04:54

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 wa

相关标签:
6条回答
  • 2020-12-24 05:21

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

    0 讨论(0)
  • 2020-12-24 05:31

    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")
    
    0 讨论(0)
  • 2020-12-24 05:35

    The only complete solution is to check for SDK version.

    if (Build.VERSION.SDK_INT < 18) {
       webView.clearView();
    } else {
       webView.loadUrl("about:blank");
    }
    
    0 讨论(0)
  • 2020-12-24 05:36

    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.

    0 讨论(0)
  • 2020-12-24 05:46

    WebView.clearView();

    This will clear the view from the webview.

    0 讨论(0)
  • 2020-12-24 05:47

    use following statement before loadData:

    view.loadUrl("javascript:document.open();document.close();");
    
    0 讨论(0)
提交回复
热议问题