[英]Can I infer the availability of sessionStorage from testing localStorage?
如果我要使用JavaScript在用戶瀏覽器中測試localStorage
,例如
var hasStorage = (function() {
try {
localStorage.setItem(mod, mod);
localStorage.removeItem(mod);
return true;
} catch (exception) {
return false;
}
}());
if (hasStorage) {
// store things in places
}
(摘自: https : //mathiasbynens.be/notes/localstorage-pattern )
我可以推斷出(如果沒有顯式檢查的話),如果hasStorage === true
,則sessionStorage
也可用,或者是否可以禁用一個而啟用另一個?
localStorage
似乎與sessionStorage
無關。 可以使用--disable-local-storage
標志啟動--disable-local-storage
,在嘗試設置localStorage
時記錄錯誤
Uncaught TypeError: Cannot read property 'setItem' of null
盡管在Chromium命令行開關的鉻表中似乎沒有官方標志來禁用sessionStorage
。 注意,鉻是使用鉻源代碼構建的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.