IE8开箱即用支持'localStorage' [英] Does IE8 out-of-the-box have support for 'localStorage'

查看:103
本文介绍了IE8开箱即用支持'localStorage'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用HTML5功能 localStorage 。根据此博客它可以使用IE8完成,但是当我尝试使用它时,我得到一个JavaScript错误'localStorage为空或不是对象'



所以我的问题是:IE8开箱即可使用 localStorage 吗?这是我的代码:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =X-UA-Compatiblecontent =IE = 8/>
< title> IE8 - DOM Storage< / title>
< script type =text / javascript>
函数Save(){
localStorage.setItem('key','value');
}
< / script>
< / head>
< body>
< button onclick =Save();>
保存
< /按钮>
< / body>
< / html>


解决方案

它支持 localStorage ,但您需要处于IE8模式(这不适用于IE7模式)。



要检查您是否在IE8模式下工作,加载开发者控制台。在顶部,确保选择了IE8模式。标准模式也不错。

您还想确认的一件事是您使用的是HTML5文档类型。您应该无法使用具有HTML5功能的XHTML文档。

 <!DOCTYPE html> 

使用此doctype不应影响您的浏览器支持。



另外,请确保您访问 window.localStorage 。它不应该是一个问题,但IE已经知道主办更多的问题。也许它正在寻找一个本地范围的 localStorage 对象?谁知道。


I am trying to use the HTML5 feature localStorage. According to this blog it can be done using IE8, however when I try to use it I get a javascript error 'localStorage is null or not an object'

So my question: can localStorage be used by IE8 out-of-the-box? Here is my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>IE8 - DOM Storage</title>
    <script type="text/javascript"> 
        function Save() {
            localStorage.setItem('key','value');            
        }        
    </script>
</head>
<body>        
    <button onclick="Save();">
        Save
    </button>  
</body>
</html>

解决方案

It does support localStorage, though you need to be in IE8 mode (this will not work in IE7 mode).

To check that you're working in IE8 mode, load up the developer console. At the top, make sure that IE8 mode is selected. Standards mode would also be nice.

One thing that you also want to make sure of is that you're using the HTML5 doctype. You shouldn't be able to use an XHTML doctype with HTML5 features.

<!DOCTYPE html>

Using this doctype should not impact your browser support.

Also, make sure you access window.localStorage. It shouldn't be an issue, but IE has been known to host weirder issues. Perhaps it's looking for a locally scoped localStorage object? Who knows.

这篇关于IE8开箱即用支持'localStorage'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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