开发者

Using UIWebView links to call a function?

开发者 https://www.devze.com 2023-01-10 16:26 出处:网络
I\'m using a UIWebView to display formatted text fro开发者_如何转开发m local HTML. Is it possible to have specific links in the HTML call Obj-C functions? For example, clicking a link to have a new vi

I'm using a UIWebView to display formatted text fro开发者_如何转开发m local HTML. Is it possible to have specific links in the HTML call Obj-C functions? For example, clicking a link to have a new view appear? Or am I resigned to using Javascript?


You can use UIWebViewDelegate:shouldStartLoadWithRequest:navigationType: to intercept the URL and do something with it. E.g.

if ([[request.URL absoluteString]compare:@"http://somelink"] == NSOrderedSame) {
  [self someFunction];
  return YES;  // return NO to prevent this link from loading
}
0

精彩评论

暂无评论...
验证码 换一张
取 消