我在webview上添加了html页面。我想在单击按钮时捕获按钮操作。这些是我的javascript代码;
<div>
<input type="button" value="Hide Bottom Menu" onClick="hideBottomMenu(true)" />
</div>
<script language="javascript">
function hideBottomMenu(isHide){
Bridge.hideBottomMenu(isHide);
}
</script>
这些是我的Objective-c代码;
我在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上的按钮时,UIWebview委托方法(shouldStartLoadWithRequest)没有调用。我想从那里捕获按钮动作。
任何人都可以帮助我吗?谢谢,哈利尔。
答案 0 :(得分:2)
您可以在http://www.joshuakehn.com/2014/10/29/using-javascript-with-wkwebview-in-ios-8.html
找到有用的内容但为此您需要使用wkwebview