iOS:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{ //js方法名+参数 NSString* jsCode = [NSString stringWithFormat:@"report('%@')",self.jsStr]; //调用html页面的js方法 [webView stringByEvaluatingJavaScriptFromString:jsCode]; }
Android:
android主要是通过WebView的webView.loadUrl("javascript:xxmethod();"); 来调用嵌入html5中的 方法。 例子如下:
a:html5 中 定义一个方法,名叫 "noParamFunction()"
<html>
<head><script>function noParamFunction() { var component = document.getElementById("noparam_ta");component.value = component.value + "native button clicked,call js with noparams\n";}</script></head></html>b: 在android本地:想调用javascript中的noParamFunction方法,如下即可
webView.loadUrl("javascript:noParamFunction();");