IE UserData 本地存储(替代localStorage)

来源:互联网 发布:如何评价汤灿 知乎 编辑:程序博客网 时间:2024/05/17 21:31

在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>

0 0
原创粉丝点击