I'm displaying some HTML with links in a UIWebView. I want the links to open in Safari after the user confirmed that the link should really be opened.
Opening the link works fine, but if the user cancels, the link remains selected and is highlighted in blue. How can I deselect the link and get rid of the highlighting?
- (BOOL)webView:(UIWebView *)aWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
self.url = request.URL;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Open the Link in Safari" message:[request.URL absoluteString] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK"];
[alert show];
[alert release];
return false;
}
return true;
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
[[UIApplication sharedApplication] openURL:url];
}
// Insert magic deselection code here
}
Update: It seems [UIWebView stringByEvaluatingJavaScriptFromString:] is the way to go. But how exactly? I tried
for (var e in document.getElementsByTag("a")) {e.blur();}
but to no avail.