How to clean the content of UIWebView without loading an empty page?

别来无恙 提交于 2019-12-02 19:09:24

You can just use this line of code :

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];

Here you will find whole demo

this did the trick for me:

 [webView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];

Try this out. This worked for me

[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];

If your only problem is that the spinner disappears when you load a blank page, you can use this code in webViewDidFinishLoad:

– (void)webViewDidFinishLoad:(UIWebView *)currentWebView {
    if (![currentWebView.request.URL.description isEqualToString: @"about:blank"]) {
        self.mySpinner.hidden = YES;
    }
}

...then the spinner will go on until your webview is actually done loading.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!