简体   繁体   中英

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?

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;

}

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM