javascript 从 html 文件夹中的 HTML5 桌面应用程序访问本地文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9250695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Access local files from HTML5 Desktop Application in html folder
提问by Mohammad Nikravan
HTML5 is great and I can replace my existing desktop application with it, but just a little security restriction prevents me to complete my job. I plan to create a simple desktop application completely with HTML5 so it can run on any mobile and desktop devices that support HTML-5.
HTML5 很棒,我可以用它替换我现有的桌面应用程序,但是只有一点点安全限制会阻止我完成我的工作。我计划完全使用 HTML5 创建一个简单的桌面应用程序,以便它可以在任何支持 HTML-5 的移动和桌面设备上运行。
I know about the browser security on local file and the reason behind it, but I don't know why I couldn't find a way to grant read-only access to a folder as sandbox. My application does not need to write a file or even does not need to read a file outside of It main html folder. It needs to read the local file just in same folder same as it do on domain.
我知道本地文件的浏览器安全性及其背后的原因,但我不知道为什么我找不到一种方法来授予对文件夹作为沙箱的只读访问权限。我的应用程序不需要写入文件,甚至不需要读取它主 html 文件夹之外的文件。它需要在与域上相同的文件夹中读取本地文件。
So please let me know:
所以请告诉我:
- Can run browser with specific command to force it grant access to local file that exists in same folder of HTML? It should not disable all local security restriction just grant HTML access to file in same folder or subfolder.
- Is it cross platform method to map a local folder as local host that work on mobile platforms?
- Is there any manifest file exists to put in folder to grant read access in same HTML folder?
- Is there any way to grant read-only access to a folder as sandbox?
- 可以使用特定命令运行浏览器以强制它授予对 HTML 同一文件夹中存在的本地文件的访问权限吗?它不应该禁用所有本地安全限制,只是授予对同一文件夹或子文件夹中文件的 HTML 访问权限。
- 将本地文件夹映射为在移动平台上工作的本地主机是否是跨平台方法?
- 是否有任何清单文件存在于文件夹中以授予同一 HTML 文件夹中的读取访问权限?
- 有什么方法可以授予对文件夹作为沙箱的只读访问权限吗?
Note: I don't want use third party solution such as XULRunner, Mozilla Prism, Adobe Air or any other third party, I need HTML-5 solution to be cross platform if there is any.
注意:我不想使用第三方解决方案,例如 XULRunner、Mozilla Prism、Adobe Air 或任何其他第三方,如果有的话,我需要 HTML-5 解决方案跨平台。
Any idea is welcome.
欢迎任何想法。
回答by Cris Stringfellow
If you need that file so much, why not just load it dynamically inside a JS script as a json object.
如果您非常需要该文件,为什么不将它作为 json 对象动态加载到 JS 脚本中。
So, in other words, put the contents of the file into a js script, and strucutre the file contents into JSON format, then load that script on load or when you require it.
因此,换句话说,将文件的内容放入 js 脚本中,并将文件内容构建为 JSON 格式,然后在加载时或需要时加载该脚本。
Alternately if you need file IO use localstorage.
或者,如果您需要文件 IO,请使用 localstorage。