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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With