Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView and click link

Tags:

ios

uiwebview

I know that most likely the answer is very obvious, but I've looked everywhere on the internet and I have not found anything. I use this method to see if the user presses on the WebView

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {

I can assure you that it works.

What I want to do is to make different actions according to the id

es

<a id="hello" href="..."><img src="..." /></a>

once the delegate detect "touch click" on the img with the "hello" id, I would do some custom stuff, like [self callSomething];

Could you show me how to do it using a sample code? thanks

like image 242
Filoo Avatar asked Jan 13 '23 13:01

Filoo


1 Answers

change your code as follows

  <a id="hello" href='didTap://image><img src="..." /></a>

and in the delegate method try like this.

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
 {     
NSString *absoluteUrl = [[request URL] absoluteString];
 NSString*temp=[absoluteUrl stringByReplacingOccurrencesOfString:@"@" withString:@""];

if ([temp isEqualToString:@"didTap://image"])
{
    [self your method];
}
return YES;
    }
like image 110
Madhu Avatar answered Jan 24 '23 04:01

Madhu