Reputation: 51
I load my html data like this:
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:url];
But when called:
[WebView goBack];
webView can not go back to that html page.
What should I do ? I appritiate any respond.
Upvotes: 0
Views: 4938
Reputation: 387
If your initial page in UIWebView is not remote page (like www.yahoo.com) but just a local html file, after clicking any link in this first page you will be redirected, but goBack
method will became unavailable for going back to the first initial page (html file).
You can use little hack for do this. The UIWebView have a readonly BOOL parameter canGoBack
, which is indicates a possibility to going back. It usually used to disable/enable "go back" button.
I am using something like this:
- (void) userPressedGoBackButton {
if ([self.webView canGoBack]) {
[self.webView goBack];
} else {
[self.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:url];
}
}
Upvotes: 2
Reputation: 1
I had the same question. The solution for myself is to create a button to go back to cached html data page. This button calls a method, which is also called in viewDidLoad to initialise the webview.
My case is loading a rss data from a website, then create html string, which is displayed with webview using loadHTMLString. There are some links on this html page, after clicking the links, the goback button works properly, but cannot go to the first page - the rss displayed page.
Upvotes: 0
Reputation: 8243
Please try something like this:
NSString *urlAddress = @"http://www.stackoverflow.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
[self.webview loadRequest:requestObj];
and then try your back navigation:
[self.webview goBack];
Upvotes: -1