IOS下的safari下localStorage不起作用的問題

用vue開發的項目在登錄的時候,無意中發現ios10.3以後版本登錄沒反應,測試時發現

此處之後無法執行,查閱資料後發現

在度娘上沒找到答案,最後到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這裏還有其他

人寫的一些方法,我沒試過。各位可以試試

發佈了31 篇原創文章 · 獲贊 7 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章