I am creating an iphone app right now and there is a UIWebView
in one of the pages. the page that gets loaded has a link, I was wondering if there is anyway to trigger a function inside the app when the link is clicked. Technically I just want to create a back button if the link was clicked.
Asked
Active
Viewed 169 times
0

Ahoura Ghotbi
- 2,866
- 12
- 36
- 65
3 Answers
2
You can implement the UIWebViewDelegate
in your view controller and get notified when the webview is about to load another webpage.
Example:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// Check here if the link was clicked by checking the request object
return YES;
}
Don't forget to call [webView setDelegate:self
] in your viewDidLoad
method (or directly hook it up in IB)

JustSid
- 25,168
- 7
- 79
- 97
-
@AhouraGhotbi Added an example – JustSid May 18 '12 at 16:48
1
Take a look here
https://stackoverflow.com/a/3742635/474535
Another article about UIWebview communication TO objective C
http://imagineric.ericd.net/2011/10/18/uiwebview-communication-to-objective-c/
-
-
yea @JustSid is right, I want it the other way around, I want the webpage to send the request to the app – Ahoura Ghotbi May 18 '12 at 16:44
-
@JustSid: I read he wants something from webview to objective c (the app) that's what the article says. Note that I updated the link. The article is about sending a string from webview to app – bart s May 18 '12 at 16:45