本文介绍了HTML5 Web存储vs Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示一条消息,首次访问我网站上特定网页的访问者。该消息只需要显示一次。
I want to display a message to first time visitors of a specific page on my site. The message will only need to appear once.
这样使用cookie会非常简单,但使用HTML5 localStorage会更有好处吗?
This would be pretty simple to do using cookies but is there more benefit to using HTML5 localStorage? If so how would it be implemented?
推荐答案
- HTML5 localStorage将更容易实现它不需要这么多的行和它很直接的如何实现。以下是一个示例:
- 这里描述的另一个选项是cookie。 Cookie是一个广泛使用的解决方案,但它需要更多的行写一个cookie,但正如上面提到的优点是cookie通过许多旧的浏览器使用的事实。以下是Cookie示例:
- HTML5 localStorage would be a lot more easier to implement it does not requires so many lines and it pretty straight forward how to implement. Here is an example: http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_webstorage_local_clickcount
- The other option that was described here is cookie. Cookie is a widely used solution but it requires more lines to write a cookie, but as it was mentioned above the advantage is the fact that cookie is used through out many old browsers. Here is an example of cookie:http://www.w3schools.com/js/tryit.asp?filename=tryjs_cookie_username
看看未来,以及浏览器,它现在成为越来越多的浏览器必须支持HTML5的要求我会考虑localStorage
Looking at the future considering the fact that OP are changing dramatically as well as browsers and it now becomes a requirement that more and more browsers have to support HTML5 I would consider localStorage
这篇关于HTML5 Web存储vs Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!