標籤:模式 查看 properly 測試 safari most mon 沒有 無法
我們的一個小應用,用localStorage做了下緩衝,測試上線之後有反饋頁面資料拉取不到,
最後定位到是localStorage有問題。
是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.‘);
}
}
複製代碼
。提示使用者關閉無痕模式。
***************************************************
try {
localStorage.setItem(key, d);
} catch (e) {
alert("您處於無痕瀏覽,無法為您儲存");
}
ios的坑