如何将button操作捕获到iOS上的JavaScript?

我在webview上添加了html页面。 我想单击button时捕捉button的动作。 这些是我的JavaScript代码;

<div> <input type="button" value="Hide Bottom Menu" onClick="hideBottomMenu(true)" /> </div> <script language="javascript"> function hideBottomMenu(isHide){ Bridge.hideBottomMenu(isHide); } </script> 

这些是我的客观规范;

我在viewdidload上调用了html页面,看到html页面没有问题。

 NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"bridge" ofType:@"html"]; NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; [_webView loadHTMLString:htmlString baseURL:nil]; 

UIWebView的委托方法;

 -(void)webViewDidFinishLoad:(UIWebView *)webView{ [_webView stringByEvaluatingJavaScriptFromString:@"hideBottomMenu()"]; } -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ return YES; } 

当我点击webview上的button时,UIWebview委托方法(shouldStartLoadWithRequest)不能调用。我想从那里捕获button操作。

有谁能够帮助我? 谢谢,Halil。

你可以在这里find有用的帮助http://www.joshuakehn.com/2014/10/29/using-javascript-with-wkwebview-in-ios-8.html

但为此,您将需要使用wkwebview