http://xiangai.taobao.com
http://shop148612228.taobao.com

HTML5 特性检测:本地存储(Local Storage ,sessionStorage)

如果你的浏览器支持该特性的话,那么全局对象:window上会有一个localStorage的属性,反之,你的浏览器不支持的话,那么该属性值为undefined

function supports_local_storage(){
    return !!window.localStorage;
}

<input type="button" onclick="Supports_localStorage()" value="Supports_localStorage"/><script type="text/javascript">    function Supports_localStorage()	{        alert(window.localStorage);	}</script>
<input type="button" onclick="Supports_sessionStorage()" value="Supports_sessionStorage"/><script type="text/javascript">    function Supports_sessionStorage() {        alert(window.sessionStorage); }</script>


同样的,如果你不想自己亲手去写这个检测方法的话,你可以使用Modernizr来检测你的浏览器是否支持本地存储。

if(Modernizr.localstorage){
  //window.localStorage is available!
}else{
  //no native support for local storage
  //maybe try Gears or another third-party solution
}
posted @ 2011-05-31 09:13  万事俱备就差个程序员  阅读(528)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏