Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
33
rated 0 times [  35] [ 2]  / answers: 1 / hits: 157375  / 12 Years ago, mon, january 28, 2013, 12:00:00

My webapp have javascript errors in ios safari private browsing:




JavaScript:error



undefined



QUOTA_EXCEEDED_ERR:DOM Exception 22:An attempt was made to add something to storage...




my code:



localStorage.setItem('test',1)

More From » html

 Answers
2

Apparently this is by design. When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage is available, but trying to call setItem throws an exception.



store.js line 73
QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.


What happens is that the window object still exposes localStorage in the global namespace, but when you call setItem, this exception is thrown. Any calls to removeItem are ignored.



I believe the simplest fix (although I haven't tested this cross browser yet) would be to alter the function isLocalStorageNameSupported() to test that you can also set some value.



https://github.com/marcuswestin/store.js/issues/42



function isLocalStorageNameSupported() 
{
var testKey = 'test', storage = window.sessionStorage;
try
{
storage.setItem(testKey, '1');
storage.removeItem(testKey);
return localStorageName in win && win[localStorageName];
}
catch (error)
{
return false;
}
}

[#80586] Friday, January 25, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;