Question

I need to save a large amount of data through web browser localStorage intercepting the instance when it fills. I searched a lot and the only way I could find is calling a boolean method which try to makes new entries. I'd prefer to avoid this method.

I would like to know if a localStorage JavaScript function to know if it's full exists.

Was it helpful?

Solution

No such method exists. The only way to test the storage capacity, is by attempting to add to storage, and catching the exception. See the spec for available methods of localStorage.

OTHER TIPS

The way normally used to prevent such interception is to add a check for the QUOTA_EXCEEDED_ERR like

try {
    localStorage.setItem('item', val);
} catch (e) {
    if (e == QUOTA_EXCEEDED_ERR) {
        alert('Quota exceeded!');
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top