所以,我认为我可以像普通对象一样循环遍历localStorage,因为它有一个长度.我怎么能循环呢?
localStorage.setItem(1,'Lorem');
localStorage.setItem(2,'Ipsum');
localStorage.setItem(3,'Dolor');
Run Code Online (Sandbox Code Playgroud)
如果我做了localStorage.length它返回3哪个是正确的.所以我假设for...in循环可行.
我想的是:
for (x in localStorage){
console.log(localStorage[x]);
}
Run Code Online (Sandbox Code Playgroud)
但无济于事.有任何想法吗?
我的另一个想法就是这样
localStorage.setItem(1,'Lorem|Ipsum|Dolor')
var split_list = localStorage.getItem(1).split('|');
Run Code Online (Sandbox Code Playgroud)
其中for...in确实有效.
我想访问保存在特定页面上的所有localStorage变量.我怎么做?我想展示它就像我将使用join()函数显示一个数组
我想显示之前写的所有密钥和存储.我的代码如下.我创建了一个函数(allStorage),但它不起作用.我怎样才能做到这一点?
function storeUserScribble(id) {
var scribble = document.getElementById('scribble').innerHTML;
localStorage.setItem('userScribble',scribble);
}
function getUserScribble() {
if ( localStorage.getItem('userScribble')) {
var scribble = localStorage.getItem('userScribble');
}
else {
var scribble = 'You can scribble directly on this sticky... and I will also remember your message the next time you visit my blog!';
}
document.getElementById('scribble').innerHTML = scribble;
}
function clearLocal() {
localStorage.clear();
return false;
}
function allStorage() {
var archive = [];
for (var i = 0; i<localStorage.length; i++) {
archive[i] = localStorage.getItem(localStorage.key(i));
}
}
Run Code Online (Sandbox Code Playgroud) 我已经存储了几个键值对,其中包含使用HTML5 localstorage变量的某些加密登录信息.我为所有关键名称添加了一个唯一的前缀TM_loginname.现在我想清除所有localstorage键值对,其键以前缀TM_开头.PS:我也尝试过sessionstorage,但只有在浏览器关闭时它才会清除.
我必须使用 Python 以自动方式访问(读取)网页。使用 Python,我可以轻松访问网页的内容(HTML 代码)以及服务器发送的 cookie。
现在,在 HTML5 中,我们有了一个新概念“本地存储”。所以,我需要修改我的 Python 脚本,以便我也可以读取存储在本地存储中的数据。
有可能这样做吗?是否有任何 Python 库可以让它变得简单?
是否无法检索我存储在sessionStorage(或localStorage)中的所有键/对象?
如果我完成了sessionStorage.name = 'John'和sessionStorage.city = 'New York',是否没有办法获取显示键name和的列表city?
我不确定IE8是否完全支持localStorage.但我使用以下方法来检测
function supports_html5_storage()
{
try {
return 'localStorage' in window && window['localStorage'] !== null;
}
catch (e) {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
现在IE在窗口中为'localStorage'返回true
但是对于window ['localStorage']返回undefined
那么我应该更新这个方法还是IE8确实有本地存储支持?