Reputation: 6402
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?
Upvotes: 31
Views: 33038
Reputation: 1153
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;
}
Upvotes: 68
Reputation: 11502
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)
Upvotes: 5
Reputation: 535945
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.
Upvotes: 36