ios的坑

來源:互聯網
上載者:User

標籤:模式   查看   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的坑

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.