Use localStorage to regularly save the edited content of ueditor as a draft.
Check the Code directly.
1, the introduction of ueditor and ueditor use I will not elaborate on the details please stamp http://blog.csdn.net/wangdianyong/article/details/39780709
2. ueditor. jsp
<Head>
<! -- Introduce jquery -->
<Script type = "text/javascript" src = "js/jQuery2.0.js"> </script>
<! -- End with jquery introduction -->
<! -- Introduce ueditor -->
<Script type = "text/javascript" src = "ueditor/ueditor. config. js"> </script>
<Script type = "text/javascript" src = "ueditor/ueditor. all. min. js"> </script>
<! -- End with ueditor introduction -->
<! -- Introduce localStorage. js -->
<Script type = "text/javascript" src = "js/localStorage. js"> </script>
<! -- Import localStorage. js to end -->
<Script type = "text/javascript">
$ (Document). ready (function (){
Var ue = UE. getEditor ('Container ');
Ue. addListener ("ready", function (){
// The editor is ready for use.
Var html = localStorage. getItem ("ctValue ");
Alert (html );
Ue. setContent (html );
});
});
</Script>
</Head>
<Body>
$ {Param. content}
<P>
<Span id = "span" name = "span"> </span>
</P>
<Form action = "ueditor. jsp" method = "post">
<Script id = "container" name = "content" type = "text/plain"
Style = "width: 800px; height: 400px;">
</Script>
<Script type = "text/javascript">
Var ue = UE. getEditor ('Container ');
</Script>
<Input type = "submit" value = "submit">
</Form>
</Body>
LocalStorage. js
$ (Document). ready (
Function (){
If (! Window. localStorage ){
Alert ('your browser does not support localStorage technology! ');
} Else {
// Var spanObj = $ ("span ");
// Alert ("spanObj" + spanObj );
Var saveTimer = setInterval (
Function (){
Var str = "";
If (document. all) {/* IE */
Str = document.frames[12.16.doc ument. body. innerHTML;
} Else {/* Chrome, ff */
// Str =
// Document. getElementById ("container"). contentDocument. body. innerHTML;
Var ue = UE. getEditor ('Container ');
Str = ue. getContent ();
}
If (str. length> 20
& (Str. indexOf (". ")>-1 | str
. IndexOf (",")>-1 )){/*
* Content is saved
* There are periods or commas (,).
*/
LocalStorage. setItem ("ctValue", str );
Var d = new Date ();
Var YMDHMS = d. getFullYear () + "-"
+ (D. getMonth () + 1) + "-"
+ D. getDate () + ""
+ D. getHours () + ":"
+ D. getMinutes () + ":"
+ D. getSeconds ();
// Alert (YMDHMS );
// SpanObj. innerHTML = '(data is stored in:' +
// YMDHMS
// + ')';
// Var text = $ ("span"). text = '(Save the data :'
// + YMDHMS + ')';
$ ("# Span"). text ('(data is stored in' + YMDHMS + ')');
// Alert (text );
SetTimeout (function (){
// SpanObj. innerText = '';
},5000 );
}
}, 25000); // save every N seconds
Function stoplocs (){
ClearInterval (saveTimer); // stop saving
// LocalStorage. removeItem ("ctValue"); // clear
}
Function showlocs (){
Var html = localStorage. getItem ("ctValue ");
Editor. setContent (html );
// Alert (localStorage. getItem ("ctValue "));
}
}
});
You can close your browser and re-open the page to find that the previously edited content is not lost due to unexpected situations.
Source code