简体   繁体   English

sessionStorage.getItem('key')可以触发异常吗? 隐身模式? 任何旧的手机浏览器?

[英]Can sessionStorage.getItem('key') trigger an exception? incognito mode? Any old mobile phone browser?

I'm curious if sessionStorage.getItem('mytestdata') ever can trigger an exception. 我很好奇sessionStorage.getItem('mytestdata') 是否会触发异常。 I'm NOT talking about 我不是在说

localStorage.setItem('key', 'value')

but rather about 而是关于

sessionStorage.getItem('key')

Thank you. 谢谢。

Yes, but just if you are using a very old version of web browser, not if a key doesn't exists. 是的,但是就算您使用的是旧版的网络浏览器,也不存在不存在的密钥。 You can check compatibility here https://developer.mozilla.org/es/docs/Web/API/Window/sessionStorage 您可以在此处检查兼容性https://developer.mozilla.org/es/docs/Web/API/Window/sessionStorage

If any item not set in localstorage then you need to check it by typeof != 'undefined' 如果未在localstorage设置任何项目,则需要通过typeof != 'undefined'进行检查

if(typeof sessionStorage.getItem('key') !== null){
  //The `key` is set in the `localStorage`
}

if(typeof sessionStorage.getItem('key') != 'undefined'){
   //The `key` and `value` both are set in the `localStorage`    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载页面时 SessionStorage.getitem 不起作用 - SessionStorage.getitem not working when loading page 有没有办法通过使用 javascript 检查浏览器是否在隐身模式下工作? - Is there any way to check browser works with incognito mode or not by using javascript? 我可以在浏览器选项卡的隐身模式下运行 html 代码吗? [等候接听] - Can i run the html code on incognito mode of browser tab? [on hold] 隐私浏览模式(隐身)下的 Web 存储(sessionStorage 和 localStorage) - Web Storage (sessionStorage and localStorage) in private browsing mode (incognito) 好像浏览器处于隐身模式一样发出获取请求? - Making a get request as if the browser is in incognito mode? sessionStorage javascript,加载getItem? - sessionStorage javascript, load getItem? 使用SessionStorage Cart的GetItem - GetItem with sessionStorage Cart 有没有办法默认允许在隐身模式下扩展? - is there any way to allow extensions in incognito mode by default? 无法从ComponentWillMount的sessionStorage中获取项目? - Cannot getItem from sessionStorage in ComponentWillMount? socket.emit无法在移动设备上运行(但它可以在隐身模式下运行) - socket.emit is not working in mobile chrome (but it works in incognito mode)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM