如何将存储在应用程序包中的javascript文件(JS)路径获取到文档目录中的html文件

时间:2014-02-23 10:15:41

标签: javascript html ios uiwebview nsbundle

I have one .js file named final.js which I copied as bundle resource I have a requirement like the html document which reads this js file should download at runtime and store it in documents directory. But the js file is not able to read by the html when I loaded it in webview, because of the path of .js file.

I tried with the solution like below, but not worked.
  

<script src ="./final.js"> </script>

最后我尝试复制下面的应用程序包的硬编码路径,现在它可以工作了。最后我才知道路径不合适。

> <script src ="/Users/unknownUser/Library/Application Support/iPhone
> Simulator/7.0/Applications/025EF3B6-F2E6-4162-8921-839D7D98FF58/HTMLGetdataTestApp.app/final.js">
> </script>`

任何人都可以告诉我存储在文档目录中的html文件如何读取存储在主束中的.js文件,该文件使用正确的路径而不是像上面那样硬编码。

1 个答案:

答案 0 :(得分:0)

简单的解决方案是将final.js文件复制到文档目录。

将js文件从bundle复制到文档目录(html页面所在的位置)并将路径设置为:

<script src ="final.js"> </script>