iOS WebView调用javascript函数无法正常工作

刘易斯

我的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;
}
克罗曼内利

在JS中,您关闭了第一行中的script标签,而忽略了该功能

您的JS应该看起来像这样

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

var title;

function testFunction(var) {
    title = var;
}
</script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章