在Windows 7上的IE11中破坏了JavaScript localStorage对象 [英] JavaScript localStorage object broken in IE11 on Windows 7

查看:1753
本文介绍了在Windows 7上的IE11中破坏了JavaScript localStorage对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Internet Explorer 11(Windows 7版本)中的 localStorage 对象包含某些函数的字符串表示,而不是您所期望的本地调用。



这只与香草JavaScript和像JSFiddle这样的网站有没有问题,但我怀疑这是因为有 localStorage 填充到位

以此HTML页面代码为例:

 < ;!DOCTYPE html> 
< script>
localStorage.setItem('test','12345');
alert(localStorage.getItem('test'));
localStorage.clear();
< / script>

除了IE11以外,我的所有浏览器都能正常工作。第一行' SCRIPT5002:预期的功能 '发生错误。



看一下这是什么类型的 setItem 函数实际上是在IE开发人员工具控制台中,表明它是一个字符串...?

  typeof localStorage.setItem ==='string'// true 

打印( setItem )的字符串显示如下:

$ p $ function() {
var result;
callBeforeHooks(hookSite,this,arguments);
try {
result = func.apply(this,arguments);
} catch(e ){
callExfterHooks(hookSite,this,arguments,result);
callExceptHooks(hookSite,this,arguments,e);
throw e;
} }
返回结果;
}

奇怪的是,并非所有函数都有已被字符串替换,例如,相应的 getItem 函数确实是一个函数并且按预期工作编辑。

pre $ typeof localStorage.getItem ==='function'// true

将文档模式(仿真)更改为10或9仍然不能解决问题,并且两者都会导致相同的错误。将文档模式更改为8会导致出现以下错误: 对象不支持此属性或方法 ,这是因为IE8不支持 localStorage



是否有其他人在Windows 7上遇到与IE11相同的问题 localStorage 对象似乎'破碎/损坏'?

解决方案

原来这是基本版本的IE11(11.0。 9600.16428)。



安装补丁以更新到11.0.9600.16476(更新版本11.0.2 - KB2898785),问题得到解决。链接到其他版本的Windows(32位等)可以在修补程序下载页面


The localStorage object in Internet Explorer 11 (Windows 7 build) contains string representations of certain functions instead of native calls as you would expect.

This only breaks with vanilla JavaScript and sites like JSFiddle have no problem with this code but I suspect it's because there are localStorage polyfills in place that correct it.

Take this HTML page code for example:

<!DOCTYPE html>
<script>
  localStorage.setItem('test', '12345');
  alert(localStorage.getItem('test'));
  localStorage.clear();
</script>

This works perfectly well in all my installed browsers except for IE11. An error occurs on the first line 'SCRIPT5002: Function expected'.

Taking a look at what type the setItem function actually is in the IE developer tools console, states that it's a string...?

    typeof localStorage.setItem === 'string' // true

Printing out the string for setItem displays the following:

"function() {
var result;
callBeforeHooks(hookSite, this, arguments);
try {
result = func.apply(this, arguments);
} catch (e) {
callExceptHooks(hookSite, this, arguments, e);
throw e;
} finally {
callAfterHooks(hookSite, this, arguments, result);
}
return result;
}"

Oddly enough, not all functions have been replaced with strings, for example, the corresponding getItem function is indeed a function and works as expected.

    typeof localStorage.getItem === 'function' // true

Changing the document mode (emulation) to 10 or 9 still doesn't resolve the problem and both result in the same error. Changing the document mode to 8 gives the following error 'Object doesn't support this property or method' which is expected since IE8 doesn't support localStorage.

Is anyone else having the same issue with IE11 on Windows 7 where the localStorage object seems 'broken/corrupt'?

解决方案

Turns out this is a problem in the base version of IE11 (11.0.9600.16428) for Windows 7 SP1.

After installing a patch to update to 11.0.9600.16476 (update version 11.0.2 - KB2898785) the issue gets resolved. Links to other versions of Windows (32-bit etc.) can be found at the bottom of the patch download page.

这篇关于在Windows 7上的IE11中破坏了JavaScript localStorage对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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