我們的一個小應用,使用百度地圖API獲取到用戶的坐標之后用localStorage做了下緩存,測試上線之后有運營同學反饋頁面數據拉取不到,
測試的時候沒有發現問題,而且2台相同的iphone一台可以一台不行,最后定位到是localStorage有問題。
但是為啥明明版本一樣的2台手機一台可以一台不行呢?
而且2台手機打印localStorage明明都是Object,奇怪了。
在度娘上沒找到答案,最后到google發現有人說是Private Browsing Mode引起的。然后查看IOS的safari沒有發現隱私設置什么的
后來點擊右下角小框框發現有個無痕瀏覽的模式。MD,關閉后一切正常
// Safari, in Private Browsing Mode, looks like it supports localStorage but all calls to setItem // throw QuotaExceededError. We're going to detect this and just silently drop any calls to setItem // to avoid the entire page breaking, without having to do a check at each usage of Storage. if (typeof localStorage === 'object') { try { localStorage.setItem('localStorage', 1); localStorage.removeItem('localStorage'); } catch (e) { Storage.prototype._setItem = Storage.prototype.setItem; Storage.prototype.setItem = function() {}; alert('Your web browser does not support storing settings locally. In Safari, the most common cause of this is using "Private Browsing Mode". Some settings may not save or some features may not work properly for you.'); } }
可以醬紫判斷。提示用戶關閉無痕模式。
或者http://stackoverflow.com/questions/14555347/html5-localstorage-error-with-safari-quota-exceeded-err-dom-exception-22-an這里還有其他
人寫的一些方法,我沒試過。各位可以試試
