zoukankan      html  css  js  c++  java
  • IE实现userData 永久存储

     

    注意:只支持IE5,及其以上的浏览器

    //需要使用 if 条件注释
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>IE 中使用userData来进行持久化数据</title>
        <link rel="stylesheet" href="">
    </head>
    <body>
        <script>
            window.onload=function(){
                var memory=document.createElement('div');
                memory.id = '_memory';
                memory.style.display = 'none';
                memory.style.behavior = "url('#default#userData')";
                document.body.appendChild(memory);
                memory.load('myStoreData');
                var name = memory.getAttribute('username');
                if(!name){
                    var name = prompt('what is your name?');
                    memory.setAttribute('username',name);
                    memory.save('myStoreData');
    
                }
            };
            function UserDataStorage(maxage){
                var memory=document.createElement('div');
                memory.id = '_memory';
                memory.style.display = 'none';
                memory.style.behavior = "url('#default#userData')";
                document.body.appendChild(memory);
                if(maxage){
                    var now = new Date().getTime();
                    var expires = now+maxage*1000;
                    memory.expires = new Date(expires).toUTCString();
                }
                memory.load('UserDataStorage');
                this.getItem=function(key){
                    return memory.getAttribute(key) || null;
                };
                this.setItem=function(key,value){
                    memory.setAttribute(key,value);
                    memory.save('UserDataStorage');
                };
                this.removeItem=function(key){
                     memory.removeAttribute(key);
                     memory.save('UserDataStorage');
                };
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    session的生命周期
    临远的spring security教程
    spring security原理图及其解释
    解决eclipse中出现Resource is out of sync with the file system问题
    从SOA到BFV【普元的一份广告文章】
    普元OA平台介绍
    门户平台
    企业门户平台解决方案
    使用 CAS 在 Tomcat 中实现单点登录
    CAS 跨域原理
  • 原文地址:https://www.cnblogs.com/jijm123/p/8433974.html
Copyright © 2011-2022 走看看