【发布时间】:2010-01-04 23:07:33
【问题描述】:
我在 UIWebView 中显示一些带有链接的 HTML。我希望在用户确认确实应该打开链接后在 Safari 中打开链接。
打开链接可以正常工作,但如果用户取消,链接将保持选中状态并以蓝色突出显示。如何取消选择链接并摆脱突出显示?
- (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
}
更新:似乎 [UIWebView stringByEvaluatingJavaScriptFromString:] 是要走的路。但具体如何?我试过了
for (var e in document.getElementsByTag("a")) {e.blur();}
但无济于事。
【问题讨论】:
标签: javascript iphone uiwebview webkit