Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView Link Click

In my app certain HTML page is loaded in a webview. I need to get click on certain label like "neuron" and should display their description in another view. How Can i get the label click and clicked label in the webview?

like image 345
PgmFreek Avatar asked Mar 09 '11 04:03

PgmFreek


3 Answers

Use the Delegate to Determine the Navigation Type!

My Snippet

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


    if (navigationType == UIWebViewNavigationTypeLinkClicked){

        NSURL *url = request.URL;
        [self openExternalURL:url];//Handle External URL here

    }

    return YES;

}
like image 147
Franky Avatar answered Sep 30 '22 00:09

Franky


By "label" do you mean "link"? If so, give the UIWebView a delegate and implement webView:shouldStartLoadWithRequest:navigationType. It will be called any time the user taps a link in the UIWebView.

like image 36
matt Avatar answered Sep 30 '22 00:09

matt


Implementing this is simple. Everytime a webview wants to load something, it will call

webView:shouldStartLoadWithRequest:navigationType

which passes in the url associated with the hyperlink. Here, you can parse the NSURLRequest argument and handle what you want to do in native code.

(Remember, return NO to stop the UIWebView from actually loading the link afterwards)

like image 28
futureelite7 Avatar answered Sep 30 '22 01:09

futureelite7