In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you an example analysis of HTML5 local storage localStorage and sessionStorage. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
LocalStorage and sessionStorage in HTML5's local storage API are used the same way, except that sessionStorage is emptied as soon as the page is closed, while localStorage is saved all the time. Taking localStorage as an example, this paper briefly introduces the local storage of HTML5, and gives some examples for common problems such as traversal.
LocalStorage is the API stored locally by HTML5. It uses key-value pairs to access data, and the accessed data can only be strings. Different browsers support the API, such as usage, maximum storage space, and so on.
I. basic usage of localStorage API
The usage of localStorage API is easy to understand. The following are common API operations and examples: set data: localStorage.setItem (key,value); example:
The code is as follows:
For (var iTun0; I 5242875 + 5 = 5242880chrome 28.0 > 2621435 + 5 = 2621440safari 5.1 > 2621435 + 5 = 2621440opera 12.15 > 5m (if you exceed it, a dialog box that allows you to request more space will pop up)
Test code reference:
The code is as follows:
Function log (msg) {console.log (msg); alert (msg);}
Var limit; var half = '1century; / / var str = half; var sstr; while (1) {try {localStorage.clear (); str + = half; localStorage.setItem (' cache', str); half = str;} catch (ex) {break;} var base = str.length; var off = base / 2; var isLeft = 1 While (off) {if (isLeft) {end = base-(off / 2);} else {end = base + (off / 2);}
Sstr = str.slice (0, end); localStorage.clear (); try {localStorage.setItem ('cache', sstr); limit = sstr.length; isLeft = 0;} catch (e) {isLeft = 1;}
Base = end; off = Math.floor (off / 2);}
Log ('limit:' + limit)
3.2 exception handling for data storage
The code is as follows:
T
Ry {localStorage.setItem (key,value);} catch (oException) {if (oException.name = = 'QuotaExceededError') {console.log (' exceeding local storage limit!') / / if the historical information is not important, you can clear it and then set localStorage.clear (); localStorage.setItem (key,value);}} the above examples of HTML5 local storage localStorage and sessionStorage shared by the editor are analyzed. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.