Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 html5 会话存储中存储一组项目。但是在将新项目存储在数组中之前,我想看看是否有足够的空间,如果没有足够的空间,我想删除第一个元素并添加新项目。我如何知道会话存储中的可用空间?
尝试将数据放在那里并捕获可能的错误:
try { sessionStorage.setItem('key', data); } catch (e) { if (e.name === 'QuotaExceededError') { /* do something else */ } }