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

有些话、适合烂在心里 提交于 2019-12-20 09:39:38

问题


I need to clean the content of UIWebView(in order to reuse it), but I have some authentication handling code in its delegate methods, so I do not want to load an empty page like about:blank to clean it, as it will trigger my authentication handling code. So is there a way for doing this? (also, by reusing it, I need to put a spinner on top of the web view, and when it loads another page, I don't want the user see the previous loaded page content, so that's why I need to clean it)

Thanks!


回答1:


You can just use this line of code :

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

Here you will find whole demo




回答2:


this did the trick for me:

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



回答3:


Try this out. This worked for me

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



回答4:


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.



来源:https://stackoverflow.com/questions/10909329/how-to-clean-the-content-of-uiwebview-without-loading-an-empty-page

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