Javascript比较2检查localStorage [英] Javascript comparing 2 checks for localStorage

查看:137
本文介绍了Javascript比较2检查localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在diveintohtml5网站上看到这个。这是他们如何检查浏览器是否支持localstorage。

I saw this in the diveintohtml5 website. This is how they check to see if localstorage is supported on the browser.

返回'localStorage'在窗口& window ['localStorage']!== null;

这和以前一样吗?

return window.localStorage!= undefined

推荐答案

p> 1

return 'localStorage' in window && window['localStorage'] !== null;

如果窗口对象包含名为 localStorage 的属性,并且该属性的值不是 null

This returns true if the window object contains a property with the name localStorage and the value of that property is not null.

2

return window.localStorage != undefined

如果 code> object包含名为 localStorage 的属性,并且该属性的值不是 undefined null
(假设全局属性 undefined 保存值 undefined

This returns true if the window object contains a propety with the name localStorage and the value of that property is not undefined or null (I am assuming that the global property undefined holds the value undefined)

这篇关于Javascript比较2检查localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆