简体   繁体   English

Web视图加载远程页面时,无法获取要执行的本地javascript文件

[英]Cannot get local javascript file to execute when web view loads a remote page

I have worked on this for several days and do not know what I am doing wrong. 我已经为此工作了好几天,不知道我在做什么错。 Any help is appreciated 任何帮助表示赞赏

  1. I have set the delegate. 我已经设置了代表。
  2. I have moved the javascript file to the Copy Bundle. 我已将javascript文件移到了副本捆绑包中。
  3. See code below. 请参见下面的代码。

     - (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *jsPath = [[NSBundle mainBundle] pathForResource:@"doc" ofType:@"js" inDirectory:NO]; NSString *js = [NSString stringWithContentsOfFile:jsPath encoding:NSUTF8StringEncoding error:nil]; [webView stringByEvaluatingJavaScriptFromString:js]; } 

My javascript file looks like this 我的JavaScript文件如下所示

<script type="text/javascript" >
alert("hello");
</script>

只需从JavaScript中删除脚本标签即可使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM