你好,我正在开发一个应用程序,我在 ios 的 webview 中打开一个菜单。
菜单是一个 html 页面。说菜单有两个选项
- 注册
- 登录
我已经开发了以下页面。
1. http://example//menu
2. http://example//register
3. http://example//login
我可以在 WebView 中打开菜单页面。现在我想做的是在 objective c 中创建一个方法,比如 openpage(url) 这个函数应该在 webview 中打开 url。
html 页面在 Android 中工作正常,我想让它在 ios 中工作。
注册onclick方法如下:
onclick="window.jsInterface.openPage('http://example//register'); return false;">
所以我需要创建一个名为 jsinterface 的接口(interface)和一个 openpage 方法。但我不清楚该怎么做。
我还想知道委托(delegate)方法如何识别注册和菜单的点击。也就是说,如果单击注册,那么我需要打开 http://example//register
页面,如果单击登录,那么我想打开 http://example//login
.
最佳答案
你可以使用webView:shouldStartLoadWithRequest:navigationType: UIWebView 的委托(delegate)方法
如果您向 UIWebView 添加委托(delegate),则每次您在 webView 中单击 HTML 页面中的任何链接时,都会调用上述方法。获取更多信息。引用THIS
关于javascript - 从远程 html 页面中指定的 javascript 调用 objective-c 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22660821/