How to pull out browsing history from uiwebview iphone

独自空忆成欢 提交于 2019-12-11 06:54:05

问题


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


回答1:


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.




回答2:


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 :)



来源:https://stackoverflow.com/questions/12088745/how-to-pull-out-browsing-history-from-uiwebview-iphone

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