A: 

I'm running into the same type of problem. Did you ever figure out why the pages loaded from the newsletter link didn't display correctly or find a solution to this problem?

A: 

the newsletters didn't load correctly(strange characters instead of german ones) because i didn't set correctly the encoding of the page. Some where UTF8 and others ISO-9..something. i've done something like this for the characters:

NSString *page = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[feed feedURL]] encoding:NSUTF8StringEncoding error:&error];
   NSLog([feed feedURL]);

   if(page == nil)
   {
    [page release];
    page = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[feed feedURL]] encoding:NSISOLatin1StringEncoding error:&error];
   }

if the encoding is not NSUTF8StringEncoding the page is nil and i change the encoding to ISO.

for the links that have _blank as target i've done something like:

pagina = [[NSMutableString alloc] initWithString:page];
     [pagina replaceOccurrencesOfString:@"" withString:@"" options:0 range:NSMakeRange(0, [pagina length])];
     [pagina replaceOccurrencesOfString:@"target=_blank" withString:@"target=""" options:0 range:NSMakeRange(0, [pagina length])];
     [pagina replaceOccurrencesOfString:@"target=\"_blank\"" withString:@"target=\"\"" options:0 range:NSMakeRange(0, [pagina length])];
     [pagina replaceOccurrencesOfString:@"TARGET=\"_blank\"" withString:@"target=\"\"" options:0 range:NSMakeRange(0, [pagina length])];
     [myWebView loadHTMLString:pagina baseURL:nil];

in the pages loaded "target" has many forms so i search for all of them...and try to replace it.

hope it helps.

SorinA.
A: 

Another problem that i had was this one

[myWebView loadHTMLString:pagina baseURL:nil];

because i was setting the baseURL to nil the webview didn't know from where to load the css, javascript files and other links from the server so the pages looked awkward.

for example if you loaded a page for an article from http://www.bla.com/article.php?id=25 the base URL could be http://www.bla.com/article.php?id=25 or http://www.bla.com and the pages should load correctly... for me it worked

Sorin

SorinA.
+2  A: 

UIWebView doesn't open target="_blank" links. Certain links don't fire UIWebViewNavigationTypeLinkClicked events. This happens when the link has the target="_blank" attribute.

To work around this problem i used the code below. It injects some javascript after the page load to remove the target attribute from all the links. After using this code i didn;t needed anymore to parse the html source and replace _blank with _self for example.

- (void)webViewDidFinishLoad:(UIWebView *)webView {
        NSString *js = @"\
        var d = document.getElementsByTagName('a');\
        for (var i = 0; i < d.length; i++) {\
            if (d[i].getAttribute('target') == '_blank') {\
                d[i].removeAttribute('target');\
            }\
        }\
        ";

        [webView stringByEvaluatingJavaScriptFromString:js];
}
SorinA.
+1  A: 

I like SorinA answer, we can make it even better by:

  • avoid obstructing javascript with var d
  • as we know we're running webkit engine we can use selectors:

...so in your UIWebViewDelegate protocol method invoke js code:

- (void) webViewDidFinishLoad: (UIWebView *) webView {
  [webView stringByEvaluatingJavaScriptFromString: @"(function($){for(var i=0;i<$.length;++i){$[i].removeAttribute('target')}})(document.querySelectorAll('a[target=_blank]'))"];
}
Mirek Rusin