Call iOS method for HTML button click

We can use custom urls for this purpose, Lets say we want to add a button1 into HTML page and we want to call “-didTapButton1” when user taps on button1.

We should have following code into HTML page that we are loading into UIWebView,

<a href="didTap://button1"><img src="button1.jpg" /></a>

Now next what we need to do is add methods from UIWebViewDelegate (To call this method the method owner needs to be the delegate for the UIWebView used),

- (BOOL)webView:(UIWebView*)aWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *absoluteUrl = [[request URL] absoluteString];
    if ([absoluteUrl isEqualToString:@"didTap://button1"]) {
        [self didTapButton1];
        return NO;
    }
    return YES;
}

And it is done!!!