使用UIWebView链接调用函数? [英] Using UIWebView links to call a function?

查看:90
本文介绍了使用UIWebView链接调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIWebView来显示本地HTML格式的文本. HTML调用Obj-C函数中是否可以有特定的链接?例如,单击链接以显示新视图?还是我辞职了使用Javascript?

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?

推荐答案

您可以使用

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
}

这篇关于使用UIWebView链接调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆