편집기 컨텐츠 실시간 저장

2228 단어
var editor = $('.xheditor').xheditor({
                tools:'mini'
            });
            
            setInterval('save()',3000);
            function save(){
                setTimeout('saveData("info",editor[0].getSource())',3000);
                setTimeout('saveData("features",editor[1].getSource())',3000);
                setTimeout('saveData("other",editor[2].getSource())',3000);
            }
            var PwStorage = {
                save : function(key, value, force) {
                    if (window.ActiveXObject) {
                        with(document.documentElement) try {
                            load(key);
                            setAttribute("value", value);
                            save(key);
                        } catch(e) {return false;}
                    } else if (window.sessionStorage) {
                        try {
                            sessionStorage.setItem(key,value);
                        } catch(e) {return false;}
                    }
                    return true;
                },
                load : function(key) {
                    var msg = '';
                    if (window.ActiveXObject) {
                        with (document.documentElement) try {
                            load(key);
                            msg = getAttribute("value");
                        } catch(e) {}
                    } else if (window.sessionStorage) {
                        try {
                            msg = sessionStorage.getItem(key);
                        } catch(e) {}
                    } else {
                        return false;
                    }
                    return msg;
                },
            }
            function saveData(key, value){
                PwStorage.save(key, value);
            }
            var msg1 = PwStorage.load('info');
            var msg2 = PwStorage.load('features');
            var msg3 = PwStorage.load('other');
            editor[0].setSource(msg1);
            editor[1].setSource(msg2);
            editor[2].setSource(msg3);

좋은 웹페이지 즐겨찾기