0

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.

Ahoura Ghotbi
  • 2,866
  • 12
  • 36
  • 65

3 Answers3

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
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/

Community
  • 1
  • 1
bart s
  • 5,068
  • 1
  • 34
  • 55
  • It looks like he wants it the other way around? – JustSid May 18 '12 at 16:42
  • 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
0

You can use URL schemes if its your own webpage

RileyE
  • 10,874
  • 13
  • 63
  • 106