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.
e.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.com/blog/localstorage-errors/
May be "QuotaExceededError"
or "W3CException_DOM_QUOTA_EXCEEDED_ERR"
depending on IE browser version/mode http://msdn.microsoft.com/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With