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

Posted

技术标签:

【中文标题】如何获取存储在应用程序包中的 javascript 文件 (JS) 路径到文档目录中的 html 文件【英文标题】:How to get the javascript file (JS) path which is stored in application bundle to html file which is there in document directory 【发布时间】:2014-02-23 10:15:41 【问题描述】:
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】:

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

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

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

【讨论】:

感谢您的回复,我已经完成了。但我的另一个要求是 final.js 文件不应该透露给外部应用程序。所以我只需要把它打包。 @KarthikMitta: AFAIK,如果您没有启用 iTunes 文件共享选项,则可以看到文档目录中的文件。 请探索 Ifunbox 软件,它可以暴露所有东西,甚至捆绑资源文件,但我的意图是至少我可以使该文件免受不了解 IFunbox 的人的影响。对于 IFunbox 也是,如果设备被 pin 锁定,那么没有人可以提取任何东西。 不客气。请在此处评论如果您随时为我的问题找到解决方案.... @KarthikMitta:当然,我会这样做。只是想到为什么不能使用委托来复制 JS 文件。当应用程序变为活动时复制 JS 文件,当它终止或转到后台时删除该文件。我知道这不是一个好的解决方案。

以上是关于如何获取存储在应用程序包中的 javascript 文件 (JS) 路径到文档目录中的 html 文件的主要内容,如果未能解决你的问题,请参考以下文章

WP8.1程序开发中,如何加载本地文件资源或安装在程序包中的资源。

如何调用ORACLE程序包中的存储过程

如何将数据库中的数据提取到 javascript 文件中并将其存储在数组中?

如何在javascript中获取redis中的所有键和值?

c++ ffmpeg如何获取RTP包中的Seq和timestamp

在运行时替换捆绑包中的图像