Use Localstorage to save Ueditor edits to a draft on a timed basis

Source: Internet
Author: User

Just look at the code.

1, the introduction of Ueditor and Ueditor use I will not elaborate on the details please poke http://blog.csdn.net/wangdianyong/article/details/39780709

2, ueditor.jsp


<!--introducing jquery--
<script type= "Text/javascript" src= "Js/jquery2.0.js" ></script>
<!--Introduction to jquery End--
<!--introduction Ueditor--
<script type= "Text/javascript" src= "Ueditor/ueditor.config.js" ></script>
<script type= "Text/javascript" src= "Ueditor/ueditor.all.min.js" ></script>
<!--introduced Ueditor end--
<!--introduction Localstorage.js--
<script type= "Text/javascript" src= "Js/localstorage.js" ></script>
<!--introduced Localstorage.js end--


<script type= "Text/javascript" >
$ (document). Ready (function () {
var UE = ue.geteditor (' container ');
Ue.addlistener ("Ready", function () {
Editor is ready before you can use it.
var html = localstorage.getitem ("Ctvalue");
alert (HTML);
Ue.setcontent (HTML);


});


});
</script>


<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= "Submission" >
</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[1].document.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 only saved
* with a period or comma
*/
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 saved in: ' +
Ymdhms
+ ') ';
// var text = $ ("span"). Text = ' (Data saved in: ')
// + ymdhms + ') ';
$ ("#span"). Text (' (Data saved in: ' + ymdhms + ') ');


// alert (text);
SetTimeout (function () {
Spanobj.innertext = ";
}, 5000);
}
}, 25000); Save once every n seconds
function Stoplocs () {
Clearinterval (Savetimer); Stop saving
Localstorage.removeitem ("Ctvalue"); Empty
}
function Showlocs () {
var html = localstorage.getitem ("Ctvalue");
Editor.setcontent (HTML);
Alert (Localstorage.getitem ("Ctvalue"));
}
}
});


The basic timing saved as a draft content is implemented, you can close your browser to reopen the page to find that their previous edits have not been lost due to unexpected circumstances.

Source




Use Localstorage to save Ueditor edits to a draft on a timed basis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.