If you are using UIImageView to display external webpages, you may come across an issue where certain links don't fire UIWebViewNavigationTypeLinkClicked events. This happens when the link has the target="_blank" attribute.
To work around this problem you can inject some javascript after the page load to remove this attribute from all the links:
- (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];
}
Looking for a quality iPhone developer? For information on my freelancing work, ![Email me [email address]](http://3.bp.blogspot.com/_xq9s4WxBMSE/Sfhv6ru2NeI/AAAAAAAAABw/gnhObFXQlNI/s400/email.png)
6 comments: