JavaScript localStorage 对象在 Windows 7 上的 IE11 中损坏

2023-08-01前端开发问题
23

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

问题描述

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

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

这只会与普通 JavaScript 中断,像 JSFiddle 这样的网站对此代码没有问题,但我怀疑这是因为有 localStorage 可以纠正它.

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.

以这个HTML页面代码为例:

Take this HTML page code for example:

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

这在我安装的所有浏览器中都运行良好,除了 IE11.第一行 'SCRIPT5002: Function expected' 出现错误.

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

看看setItem函数在IE开发者工具控制台中实际是什么类型,说明它是一个字符串...?

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

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

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;
}"

奇怪的是,并不是所有的函数都被字符串替换了,例如,对应的getItem函数确实是一个函数,并且按预期工作.

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

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

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.

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

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

推荐答案

原来这是 Windows 7 SP1 的基本版本 IE11 (11.0.9600.16428) 中的问题.

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

安装补丁后更新到11.0.9600.16476(更新版本 11.0.2 - KB2898785)问题得到解决.可以在 补丁下载页面.

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.

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

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125