HTML5网络存储:不同的网站可以在用户计算机上覆盖彼此的数据吗? [英] HTML5 web storage: can different websites overwrite each other’s data on a user’s computer?

查看:106
本文介绍了HTML5网络存储:不同的网站可以在用户计算机上覆盖彼此的数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对HTML5存储的概念有一些疑问.我经历了相同的w3c规范,书籍和教程,但是对于某些概念我仍然不清楚:

假设我访问网站A.某些JavaScript在我的浏览器中运行,该浏览器设置了一个键值对,例如('username','deepak').然后,我访问网站B,该网站还在本地存储中添加了一个键值对('username','mahalingam').

  • 他们将如何区分?
  • 网站B是否会覆盖网站A在我的本地存储中设置的值?
  • 我们如何确保网站不会删除我的所有本地存储?

解决方案

本地存储隐私

网站A和网站B将拥有自己的本地存储.通常,您必须将某些信息存储在服务器数据库中,然后将其同步到本地存储.

我将使用本地存储作为高速缓存来一次获取数据并根据特定的时间间隔更新数据,具体时间取决于我希望何时使高速缓存失效.例如,当用户A注销并且用户B要登录时,您可以与服务器同步.

请参阅Web存储HTML5规范中的隐私部分. >

此处提供了更多信息和资源: HTML5岩石.

测试

我建议使用本地服务器设置(例如Linux/Mac/Windows,Apache,MySQL,PHP堆栈(LAMP/MAMP/WAMP))在本地主机(127.0.0.1)上进行测试.

由于HTML5规范的建议,大多数浏览器会将每个窗口和选项卡的每个域限制为 5 MB .

我还没有尝试过,但是您也许可以看看在Apache的 httpd.conf 中更改本地主机的端口号(为此,请找到Listen并更改端口关联),看看是否可以解决问题.基本上,您在不同的端口号上运行每个测试,以具有每个测试的整个存储限制.

一种替代方法是创建一个Chrome扩展程序.您可以在此处阅读有关此内容的更多信息:

I have a few questions regarding the concept of HTML5 storage. I went through the w3c specification, books and tutorials on the same, but still I am a bit unclear about certain concepts:

Assume that I access Website A. Some JavaScript runs in my browser that sets a key value pair, say ('username','deepak'). Then I access Website B which also adds a key,value pair in the localstorage as ('username','mahalingam').

  • How will they both be differentiated?
  • Will Website B override the value set by website A in my localstorage?
  • How can we ensure that a website would not erase all of my localstorage?

解决方案

Local Storage Privacy

Website A and Website B would have their own local storage. Usually you would have to store certain information in a server database and sync it to the local storage.

I would use the local storage as a cache to get data once and update it at a certain interval depending on when I would want to invalidate the cache. For instance, you could sync with the server when the user A would log out and user B would want to login.

Have a look at the Privacy section in the HTML5 spec for Web Storage.

More information information and resources here: HTML5 Rocks.

Testing

I would suggest the use of a local server setup such as Linux/Mac/Windows, Apache, MySQL, PHP stack (LAMP/MAMP/WAMP) to test on localhost (127.0.0.1).

Most browsers will limit you to 5 MB per domain for every window and tab because of the HTML5 spec recommendation.

I haven't tried this, but you could perhaps have a look at changing the port number of the localhost in Apache's httpd.conf (to do so, find Listen and change the port associated to it) and see if this will do the trick. Basically, you run each test under a different port number to have the whole storage limit for each test.

An alternative would be to create a Chrome extension. You can read more information about this here:

这篇关于HTML5网络存储:不同的网站可以在用户计算机上覆盖彼此的数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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