zoukankan      html  css  js  c++  java
  • Native App执行JS

    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 ";
    }
    </script>
    </head>
    </html>

    b: 在android本地:想调用javascript中的noParamFunction方法,如下即可

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

  • 相关阅读:
    centos/7下安装mysql5.7
    ubuntu下用vagrant搭建集群环境
    ubuntu下pyspark的安装
    Ubuntu下teamviewer的安装
    volatile(一)
    synchronized(九)
    synchronized(八)
    synchronized(七)
    synchronized(六)
    synchronized(五)
  • 原文地址:https://www.cnblogs.com/wanyakun/p/4587898.html
Copyright © 2011-2022 走看看