【发布时间】:2023-03-11 19:35:01
【问题描述】:
我在 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) 没有调用。我想从那里捕获按钮操作。
有人可以帮我吗?谢谢你,哈利尔。
【问题讨论】:
标签: javascript html ios objective-c webview