Using UIWebView links to call a function?

2019-08-28 19:06发布

I'm using a UIWebView to display formatted text from 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?

1条回答
Fickle 薄情
2楼-- · 2019-08-28 19:50

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
}
查看更多
登录 后发表回答