Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear back forward list in UIWebview on iPhone?

I want to access/clear the back forward list as if the UIWebView is new again. Is there any public API or workaround to do this?

I've tried:

while ([webview canGoback]) {
    [webview goBack];
}

but that will freeze the device (simulator too).

like image 601
zsniperx Avatar asked Sep 26 '10 21:09

zsniperx


2 Answers

Disclaimer
As with anything like this, bear in mind that the results may not make it through app store approval and may not work at-all with future revisions of the SDK.


There is no official method for doing this in the SDK. However if you really want to clear the back/forward history of a UIWebView it can be done with a little delve into the private frameworks.

A quick and dirty way to do it (complete with a bunch of ugly compiler warnings) is as follows:

Given that myUIWebViewInstance is a perfectly normal instance of UIWebView:

id internalWebView=[[myUIWebViewInstance _documentView] webView];       
[internalWebView setMaintainsBackForwardList:NO];
[internalWebView setMaintainsBackForwardList:YES];

There is also the rather tempting _clearBackForwardCache method in the framework, however it didn't seem to do much when tickled. Just flipping the boolian worked a treat for me.

like image 78
Samscam Avatar answered Nov 15 '22 19:11

Samscam


Just recreate the webview. it would reset everything including history.

like image 43
rehan Avatar answered Nov 15 '22 20:11

rehan