[英]Can I infer the availability of sessionStorage from testing localStorage?
If i were to test for localStorage
in the users browser with JavaScript, eg 如果我要使用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
}
(from: https://mathiasbynens.be/notes/localstorage-pattern ) (摘自: https : //mathiasbynens.be/notes/localstorage-pattern )
Can I infer (without explicit checks) that if hasStorage === true
, then sessionStorage
is also available, or is it possible to have one disabled with the other enabled? 我可以推断出(如果没有显式检查的话),如果
hasStorage === true
,则sessionStorage
也可用,或者是否可以禁用一个而启用另一个?
localStorage
does not appear to be related to sessionStorage
at chromium. localStorage
似乎与sessionStorage
无关。 It is possible to launch chromium with --disable-local-storage
flag which logs error when trying to set localStorage
可以使用
--disable-local-storage
标志启动--disable-local-storage
,在尝试设置localStorage
时记录错误
Uncaught TypeError: Cannot read property 'setItem' of null
though there does not appear to be an official flag to disable sessionStorage
at chromium List of Chromium Command Line Switches . 尽管在Chromium命令行开关的铬表中似乎没有官方标志来禁用
sessionStorage
。 Note, chrome is built using chromium source code. 注意,铬是使用铬源代码构建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.