IE6~IE8 UserData localStorage

        <script type="text/javascript">

            $(document).ready(function(){

                if (!$.support.leadingWhitespace){

                    if (!window.UserData) {

                        window.UserData = function (file_name) {

                            if (!file_name) {

                                file_name = "user_data_default";

                            }

                            var dom = document.createElement('input');

                            dom.type = "hidden";

                            dom.addBehavior("#default#userData");

                            document.body.appendChild(dom);

                            dom.save(file_name);

                            this.file_name = file_name;

                            this.dom = dom;

                            return this;

                        };

                    window.UserData.prototype = {

                        setItem: function (k, v) {

                            this.dom.setAttribute(k, v);

                            this.dom.save(this.file_name);

                        },

                        getItem: function (k) {

                            this.dom.load(this.file_name);

                            return this.dom.getAttribute(k);

                        },

                        removeItem: function (k) {

                            this.dom.removeAttribute(k);

                            this.dom.save(this.file_name);

                        },

                        clear: function () {

                            this.dom.load(this.file_name);

                            var now = new Date();

                            now = new Date(now.getTime() - 1);

                            this.dom.expires = now.toUTCString();

                            this.dom.save(this. file_name);

                        }

                    };

                    try{

                        window.localStorage = new window.UserData("local_storage");

                    }catch(e){

                        

                    }

                }

            }

        });

 

        </script>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327042046&siteId=291194637