【问题标题】:Ios webview calling javascript function wont workios webview调用javascript函数不起作用
【发布时间】:2013-10-13 20:34:45
【问题描述】:

我的 Objective-c 代码如下所示:

NSString *test = [NSString stringWithFormat: @"testFunction(%@)", details.name];

NSString *userName = [webView stringByEvaluatingJavaScriptFromString:test];
NSLog(@"Web response: %@",test);

这会打印出testFunction(the string of details.name here)

我的 javascript 看起来像这样:

<script type="text/javascript">document.write(title);</script>

var title;

function testFunction(var) {
    title = var;
}

【问题讨论】:

    标签: javascript ios objective-c uiwebview uiwebviewdelegate


    【解决方案1】:

    在 JS 中,您在第一行关闭了脚本标记,省略了函数

    你的 JS 应该是这样的

        <script type="text/javascript">document.write(title);
    
    var title;
    
    function testFunction(var) {
        title = var;
    }
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-11-09
      • 2017-10-15
      • 2014-08-17
      • 2021-11-09
      相关资源
      最近更新 更多