Question

I want to store an array of items in html5 session storage. But before storing new items in array I want to see if there is enough space and if it doesn't has enough I want remove first element and add new item. How I can know about available space in session storage?

Was it helpful?

Solution

Try to put the data there and catch possible error:

try {
    sessionStorage.setItem('key', data);
} catch (e) {
    if (e.name === 'QuotaExceededError') {
        /* do something else */
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top