javascript 不推荐使用 globalstorage。请改用localstorage
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9835974/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
use of globalstorage is deprecated. please use localstorage instead
提问by convergedtarkus
I got this message when doing some javascript programming, and after some google searches, I have no idea what it means, or how i cause this error. I'm including the code below, can someone explain it to me or point me to a resource on how to fix it or what is happening at all? The weird thing is that I have other code just like this part in my program, and it never gives me errors about them, so i'm really confused. Also, I only get this error to display with firebug running, else wise it just doesn't work and no error message is displayed. I also tried it in Chrome, and had the same issues, no error message but the code doesn't work.
我在做一些 javascript 编程时收到了这条消息,经过一些谷歌搜索,我不知道这意味着什么,或者我是如何导致这个错误的。我包含下面的代码,有人可以向我解释它或指向我有关如何修复它或发生了什么的资源吗?奇怪的是,我的程序中还有其他与此部分类似的代码,它从来没有给我错误信息,所以我真的很困惑。此外,我只会在运行 firebug 时显示此错误,否则它就不起作用,并且不会显示任何错误消息。我也在 Chrome 中尝试过,遇到了同样的问题,没有错误消息,但代码不起作用。
foundTextFn = function(){
console.log('fire');
if (foundTextArrayPosition != foundTextArray.length){
writeText(foundTextArray[foundTextArrayPosition],"happy");
foundTextArrayPosition += 1;
}
foundTextFnTimer=setTimeout("foundTextFn()",4000);
}
Here is another of my methods, it is basically the same thing, but it works fine. And if it matters, all of these variables are global variables declared at the start of my file as var foundTextArrayPosition = 0; for example.
这是我的另一种方法,它基本上是一样的,但效果很好。如果重要的话,所有这些变量都是在我的文件开头声明为 var foundTextArrayPosition = 0; 的全局变量。例如。
awayFn = function(){
if (awayArrayPosition != awayArray.length){
if (changeAwayState){
changeAwayState = false;
writeText(awayArray[awayArrayPosition],"normal");
awayArrayPosition ++;
temp = pickRandomSpot();
randomX = temp[0];
randomY = temp[1];
}
else{
changeAwayState = true;
}
awayTimer=setTimeout("awayFn()",10000);
}
else{
abandoned = true;
whyGoneArrayPosition = 0;
whyGoneFn();
}
}
回答by Waynn Lue
This is a deprecation error in Firefox 9. globalstorage
was a way to store data in Firefox, but HTML5 introduced localstorage
, which is now the preferred way (using window.localStorage
).
这是 Firefox 9 中的弃用错误。globalstorage
是一种在 Firefox 中存储数据的方式,但 HTML5 引入了localstorage
,现在是首选方式(使用window.localStorage
)。
https://developer.mozilla.org/en/DOM/Storagehas more information.
回答by mr-euro
Probably not related to the issue above but I will put it here for the search engines.
可能与上述问题无关,但我会将其放在这里供搜索引擎使用。
I got the same error message while doing some simple jQuery:
在执行一些简单的 jQuery 时,我收到了相同的错误消息:
Use of globalStorage is deprecated. Please use localStorage instead.
[Break On This Error]
$(document).ready(function() {
It was however due to forgetting to actually include the link href to the jQuery.js file...!
然而,这是由于忘记实际将链接 href 包含到 jQuery.js 文件中......!
回答by Fredz
I got the same error message and found a solution and perhaps the underlying cause of conflict, I was using the jQuery validate function in the jzaefferer.github.com/jquery-validation/jquery.validate.js library along with jQuery 1.7.1
我收到了相同的错误消息并找到了解决方案,也许是冲突的根本原因,我在 jzaefferer.github.com/jquery-validation/jquery.validate.js 库中使用了 jQuery 验证函数以及 jQuery 1.7.1
The problem:
I used $(document)
.ready with two different contexts
. One with the noConflict
wrapper and one without. By keeping both the same, the error message went away. Hooray!
问题:我将$(document)
.ready 与两个不同的contexts
. 一个有noConflict
包装,一个没有。通过保持两者相同,错误消息消失了。万岁!
The wrapper:
包装器:
jQuery.noConflict();
jQuery(function($) {
$(function() {
$(document).ready(function() { ...}
});
});
See also this poston my blog.
又见这个职位上我的博客。