IE UserData 本地存储(替代localStorage)
2015-01-12 15:38
190 查看
在Ie9 及以下可以使用,以上版本需要使用localstorage
参考文章
http://msdn.microsoft.com/zh-cn/vstudio/ms531424
过期
http://msdn.microsoft.com/zh-cn/vstudio/ms531095
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="gbk">
</head>
<body>
<input type="text" id="myInput">
<div id="write" onclick="writea()">设置</div>
<div id="read" onclick="reada()">读取</div>
</body>
<script type="text/javascript">
var mainObj = document.documentElement;
function writea() {
if (!mainObj.style.behavior) {
mainObj.style.behavior = 'url(#default#userData)';
}
var oTimeNow = new Date(); // Start Time
// 超时时间1分钟
oTimeNow.setMinutes(oTimeNow.getMinutes() + 1);
var sExpirationDate = oTimeNow.toUTCString();
mainObj.expires = sExpirationDate;
mainObj.setAttribute("MyData", document.getElementById("myInput").value);
mainObj.save("FirstUserDataStore");
}
function reada() {
try {
mainObj.load("FirstUserDataStore");
document.getElementById("myInput").value = mainObj.getAttribute("MyData");
}
catch (e) {
alert("没有数据 或者已经过期");
}
}
</script>
</html>
参考文章
http://msdn.microsoft.com/zh-cn/vstudio/ms531424
过期
http://msdn.microsoft.com/zh-cn/vstudio/ms531095
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="gbk">
</head>
<body>
<input type="text" id="myInput">
<div id="write" onclick="writea()">设置</div>
<div id="read" onclick="reada()">读取</div>
</body>
<script type="text/javascript">
var mainObj = document.documentElement;
function writea() {
if (!mainObj.style.behavior) {
mainObj.style.behavior = 'url(#default#userData)';
}
var oTimeNow = new Date(); // Start Time
// 超时时间1分钟
oTimeNow.setMinutes(oTimeNow.getMinutes() + 1);
var sExpirationDate = oTimeNow.toUTCString();
mainObj.expires = sExpirationDate;
mainObj.setAttribute("MyData", document.getElementById("myInput").value);
mainObj.save("FirstUserDataStore");
}
function reada() {
try {
mainObj.load("FirstUserDataStore");
document.getElementById("myInput").value = mainObj.getAttribute("MyData");
}
catch (e) {
alert("没有数据 或者已经过期");
}
}
</script>
</html>
相关文章推荐
- 使用localStorage替代cookie做本地存储,例如最近浏览历史记录
- html5本地存储localStorage 存储json对象存储格式问题
- 本地存储(localStorage、sessionStorage、web Database)
- JavaScript本地存储实践localStorage
- HTML5 LocalStorage 本地存储
- js本地存储解决方案——localStorage与userData
- HTML5本地存储localStorage、sessionStorage基本用法、遍历操作、异常处理等
- html5本地存储(localStorage)使用介绍
- HTML5本地存储Localstorage
- JS实现本地存储信息的方法(基于localStorage与userData)
- js本地存储解决方案(localStorage与userData)
- Js 操作浏览器本地存储对象:HTML5 localstorage
- HTML5本地存储localStorage与sessionStorage
- 本地存储localStorage以及它的封装接口store.js的使用
- HTML5 LocalStorage 本地存储
- HTML5 LocalStorage 本地存储
- HTML5 LocalStorage 本地存储
- JavaScript本地存储实践(html5的localStorage和ie的userData)
- 本地存储localStorage的用法总结
- html5-localStorage本地存储和SQLLite本地数据库