问题
I use formatted text in UIWebView, i have something like this:
<a href="tel://0442059840">0442059840</a>
I need to show alert to the user when clicking on that link using the UIAlertView
for confirmation before launching the telephone call. Is this possible? Thanx in advance.
回答1:
Yes but you need to use undocumented method for this. Search on google or stackoverflow you will find it easily. Here is a link for helping you.
http://dblog.com.au/iphone-development/iphone-sdk-tip-firing-custom-events-when-a-link-is-clicked-in-a-uiwebview/
回答2:
Override the delegate method
webView:shouldStartLoadWithRequest:navigationType:
and do the cjhanges as in the code I added.
Following code may help you :
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
if([urlString isEqualToString:@"tel://0442059840"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Title", nil)
message:NSLocalizedString(@"Message", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil];
[alert show];
[alert release];
}
return YES;
}
来源:https://stackoverflow.com/questions/6593991/show-alert-view-when-click-on-a-link