适用于离线网站的HTML5 localStorage [英] HTML5 localStorage for offline websites

查看:193
本文介绍了适用于离线网站的HTML5 localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的应用程序,用户可以将其下载到他/她的计算机上,然后通过硬盘驱动器打开它。我需要它能够使用任何标准浏览器存储数据。 (虽然不必在浏览器之间访问数据)。

I'm creating a simple app that a user will download onto his/her computer and then open it with a browser off the harddrive. I need it to be able to store data, using any of the standard browsers. (Although data does not have to be accessible between browsers).

这个链接,如果使用HTML5的本地存储,Internet Explorer中抛出一个错误,如果该网站的网址是像文件:/// C:/Web/mylocaltodo.html 。它说它可以通过使用'localhost'来实现,但它提供的示例应用程序并不知道如何完成这项工作。

As described by this link, If using HTML5's localstorage, Internet Explorer throws an error if the url of the site is something like file:///C:/Web/mylocaltodo.html. It says it can be gotten round by using 'localhost', but the sample application it provides doesn't how how this would be done.

是否可以在本地为离线站点保存数据,而无需用户在localhost上安装Web服务器?并且它适用于任何现代浏览器,包括Internet Explorer?

Is it possible to save data locally for an offline site without the user installing a web server on localhost? And have it work on any modern browser, including Internet Explorer?

谢谢

推荐答案

虽然问题仍然存在,但在创建应在多个窗口之间同步的应用程序时,我遇到了类似的问题。

Although the question is still old, I was facing a similiar problem when creating an application that should synchronize between multiple windows.

所以我只是想与其他开发人员分享我的经验,这可能会避免长时间搜索问题。

So I'd just like to share my experiences with other developers, that may avoid a long search for the problem.

事实上,由于同源策略(对于通过的XMLHttpRequest ) ,访问被拒绝读取 localStorage ,因此更改不会在窗口之间同步。

In fact, due to the same origin policy (as for local file access via XMLHttpRequest), access is denied for reading the localStorage, so that changes won't get synchronized between windows.

简而言之:如果您使用 file:/// 作为URL,则无法同步localStorage。使用简单的网络服务器和 http:// localhost / 作为URL,它将会。

In short: If you're using file:/// as URL, it won't be able to synchronize the localStorage. Using a simple webserver and http://localhost/ as URL, it will.

奇怪的行为,遗憾的是,javascript控制台中没有错误消息。在离线尝试一些 localStorage 实验时请记住这一点,不要在代码中疯狂搜索问题; - )

Strange behavior and sadly, there is no error message in the javascript console. Keep that in mind when trying out some localStorage experiments offline and don't get crazy searching for the issue in your code ;-)

这篇关于适用于离线网站的HTML5 localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆