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]; }
Brilliant, thanks! -Jacob
ReplyDeleteYou are a genius!! What a find! I was struggling to find a solution and it never crossed my mind to use an actual web technology such as Javascript to solve the problem.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGREAT!!!! That was exactly what I was looking for!!
ReplyDeleteVery useful! Thanks for sharing.
ReplyDeleteThis worked amazingly! Thanks very much.
ReplyDeleteGreat – I must say! I am impressed with your website and I had no trouble navigating through all tabs. The information you shared with us is really fantastic and very useful. I feel as you know what I wanted. Reasonably unusual. Excellent task.
ReplyDeleteThis is exactly what I needed - thanks very much.
ReplyDeleteI have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteappvn
kissanime alternatives
Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post. Martin Zhao
ReplyDelete