JohnC
JohnC

Reputation: 221

How to pull out browsing history from uiwebview iphone

How can i get the browsing history in UIWebView Iphone. UIWebView recorded browsing history ? if yes, How to pull out back this history shown in table view as Safari .

Please advice me. Any suggestion.

Thanks

Upvotes: 1

Views: 1896

Answers (2)

mpemburn
mpemburn

Reputation: 2884

It's actually much simpler than creating your own stack (which is what I was about to do until I found that it's not necessary). UIWebView has the methods: goBack, goForward, canGoBack and canGoForward. You can do the following.

Make the ViewController that contains your UIWebView a delegate of UIWebViewDelegate:

Create the IBActions for the buttons:

- (IBAction) browserBack: (id)sender
{
    [webBrowser goBack];
}

- (IBAction) browserForward: (id)sender
{
    [webBrowser goForward];
}

Create your Back and Forward buttons and link them to the IBActions as well as to the appropriate IBOutlets

Finally add the webViewDidFinishLoad delegate method:

- (void) webViewDidFinishLoad: (UIWebView *)webView
{
    [mBackButton setEnabled: [webBrowser canGoBack]];
    [mForwardButton setEnabled: [webBrowser canGoForward]];
}

Note that the buttons are enabled and disabled according to whether the are back or forward pages from your current position.

That's it! You will now be able to browse backward and forward, and the buttons will automatically show or be disabled as appopriate.

Upvotes: 3

Quang Hà
Quang Hà

Reputation: 4746

This method will be call when webview load a request:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

Save this request to a stack. This stack is Webview's History.

Hope that help :)

Upvotes: -1

Related Questions