uiwebview can't go backward

600 views Asked by At

I am using one html code snippet to fetch TWITTER FEEDS, code is working fine but once navigating to the twitter feeds I can't go back to the previous page.

I am loading this html content as follow :

NSString *twitterFeed = @" <a class=\"twitter-timeline\" href=\"https://twitter.com/search?q=%23diabetes+OR+%23bloodglucose+OR+%23insulin+OR+%23insulinpump+OR+%23type2+OR+%23type1\" data-widget-id=\"386089263655178240\">Tweets about \"#diabetes OR #bloodglucose OR #insulin OR #insulinpump OR #type2 OR #type1\"</a> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\"://platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>";

if (appDelegate.isReachable)
{
    [self.webView loadHTMLString:twitterFeed baseURL:nil];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"No internet connection !!" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil];
    [alert show];
}

also I am using following code to go back in webview

if ([self.webView canGoBack])
{
    NSLog(@"Can go BACK");
    [self.webView goBack];
}

still I am not able to go back. please help me how to do this?

1

There are 1 answers

2
Audun Kjelstrup On

The reason go back does not work, is that your twitter widget is loading content via XMLHTTPRequests, and thus there is no pages in the history to go back to. I tried clicking a hash-tag, and then the "Install app" button. This created a request which where put in the web views history that I could go back from.

Try loading your web view from an URL like stackoverflow.com, and you'll see that your objective-c code works as intended, and that it is the twitter-widget which does not create a browsing history to go back in.