Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 948
hzxu Avatar asked Jun 06 '12 06:06

hzxu


3 Answers

You can just use this line of code :

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

Here you will find whole demo

like image 122
Nilesh Kikani Avatar answered Nov 18 '22 17:11

Nilesh Kikani


this did the trick for me:

 [webView stringByEvaluatingJavaScriptFromString:@"document.open();document.close()"];
like image 43
myeyesareblind Avatar answered Nov 18 '22 16:11

myeyesareblind


Try this out. This worked for me

[self.webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
like image 8
Prasad Avatar answered Nov 18 '22 15:11

Prasad