如何将按钮操作捕获到ios上的javascript? [英] How to capture button action into javascript on ios?

查看:77
本文介绍了如何将按钮操作捕获到ios上的javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 < div> 
< input type =buttonvalue =隐藏底部菜单onClick =hideBottomMenu(true)/>
< / div>
< script language =javascript>
函数hideBottomMenu(isHide){
Bridge.hideBottomMenu(isHide);
}
< / script>

这些是我的objective-c代码;

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

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

UIWebView委托方法;

   - (void)webViewDidFinishLoad:(UIWebView *)webView {
[_webView stringByEvaluatingJavaScriptFromString:@hideBottomMenu()];

$ b - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

return YES;
}

当我点击webview上的按钮时,UIWebview委托方法(shouldStartLoadWithRequest) 。我想从那里捕捉按钮动作。



任何人都可以帮助我吗?谢谢Halil。

解决方案

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



但为此,您需要使用wkwebview


I added html page on webview. I want to capture button action when I click the button. These are my javascript codes;

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

These are my objective-c codes;

I called html page on viewdidload, there is no problem to see html page.

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

UIWebView delegate methods;

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    [_webView stringByEvaluatingJavaScriptFromString:@"hideBottomMenu()"];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{

    return YES;
}

When I click the button on webview, UIWebview delegate method (shouldStartLoadWithRequest) not calling.I want to capture button action from there.

Can anybody help me? Thank you, Halil.

解决方案

you can find something useful helpful here http://www.joshuakehn.com/2014/10/29/using-javascript-with-wkwebview-in-ios-8.html

but for this you would need to use wkwebview

这篇关于如何将按钮操作捕获到ios上的javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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