Native App執行JS

iOS:javascript

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
    //js方法名+參數
    NSString* jsCode = [NSString stringWithFormat:@"report('%@')",self.jsStr];
    
    //調用html頁面的js方法
    [webView stringByEvaluatingJavaScriptFromString:jsCode];
    
}html

 

Android:html5

android主要是經過WebView的webView.loadUrl("javascript:xxmethod();"); 來調用嵌入html5中的 方法。 例子以下:java

a:html5 中 定義一個方法,名叫 "noParamFunction()"android

<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>web

b: 在android本地:想調用javascript中的noParamFunction方法,以下便可lua

webView.loadUrl("javascript:noParamFunction();");component

相關文章
相關標籤/搜索