admin管理员组文章数量:1279177
I'm using html5's localStorage API.
I want to catch the QUOTA_EXCEEDED_ERR
so I can show a message to the user like "Memory is full. Cannot save. Maybe delete a few items?"
The code that I will use is like
function save() {
try {
localStorage.setItem(key, name);
} catch (e) {
if (e.name === 'QUOTA_EXCEEDED_ERR') {
alert("Memory is full. Cannot save. Maybe delete a few items?");
} else {
alert("Something went wrong? Try again later?")
}
}
}
I want to ask you, is this ok? Will this work fine to all browsers? Will work fine or break, anyways?
Of course I am testing it too, but I thought I should ask anyways, because maybe I am missing something.
I'm using html5's localStorage API.
I want to catch the QUOTA_EXCEEDED_ERR
so I can show a message to the user like "Memory is full. Cannot save. Maybe delete a few items?"
The code that I will use is like
function save() {
try {
localStorage.setItem(key, name);
} catch (e) {
if (e.name === 'QUOTA_EXCEEDED_ERR') {
alert("Memory is full. Cannot save. Maybe delete a few items?");
} else {
alert("Something went wrong? Try again later?")
}
}
}
I want to ask you, is this ok? Will this work fine to all browsers? Will work fine or break, anyways?
Of course I am testing it too, but I thought I should ask anyways, because maybe I am missing something.
Share Improve this question edited Mar 14, 2014 at 18:23 code-jaff 9,3304 gold badges37 silver badges56 bronze badges asked Oct 24, 2013 at 19:33 slevinslevin 3,88621 gold badges76 silver badges140 bronze badges2 Answers
Reset to default 10e.name
for a quota exceeded error won't always necessarily be "QUOTA_EXCEEDED_ERR"
in every browser.
It may be "NS_ERROR_DOM_QUOTA_REACHED"
in certain versions of FF http://chrisberkhout./blog/localstorage-errors/
May be "QuotaExceededError"
or "W3CException_DOM_QUOTA_EXCEEDED_ERR"
depending on IE browser version/mode http://msdn.microsoft./en-us/library/ie/cc197050(v=vs.85).aspx
However, you are still catching the error. So worst case scenario is the user will get the "Something went wrong?" alert vs. the "Memory is full" alert.
You'd better use 'Disk storage' instead of 'Memory', because it is more clear. 'Memory' is more often stands for RAM, not persistent storage
本文标签: javascriptcatch QUOTAEXCEEDEDERR on localStorageStack Overflow
版权声明:本文标题:javascript - catch QUOTA_EXCEEDED_ERR on localStorage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741226368a2361936.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论