Javascript比较2检查localStorage [英] Javascript comparing 2 checks for 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屋!