您的位置:首页 > 其它

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: