Show alert view when click on a link

2019-02-26 05:28发布

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.

2条回答
神经病院院长
2楼-- · 2019-02-26 05:38

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;
}
查看更多
时光不老,我们不散
3楼-- · 2019-02-26 05:57

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/

查看更多
登录 后发表回答