繁体   English   中英

结合使用WebStorage API和WordPress TinyMCE编辑器

[英]Using WebStorage API with WordPress TinyMCE editor

我想保留用户使用WebStorage API写入WordPress TinyMCE编辑器中的数据 我在一个插件的前端启动了编辑器。

条件是,填满文本区域后,用户可以选择是注册还是登录,并且在这种状态下,他们需要刷新页面。 我希望即使在刷新页面后也将键入的文本保留在[启用编辑器]的文本区域中。 我认为webStorage将是关键。

但是我无法将javascript(jQuery)触发到启用TinyMCE编辑器的字段中。 我可以在'tinymce' => false使它工作。

有什么办法可以保存webStorage onKeyUp,或者:

  • 将JavaScript注入TinyMCE,或者
  • 用其他方法?

尝试用类似这样的方法初始化TinyMCE,我不知道这是否对您有帮助,但是我为您用手指交叉了..我也评论了保存localstorage obj的问题,因此施加了一些限制。

 // initialize tinymce: // I loaded it over inline element (div) only cause StackOverflow editor // can't init normal tinymce with iframe.. // you have to replace only this div with your custom textare and give it ID // and reference it in code // I have choosen to save text on blur but you can do whatever event you need to update localstorage object tinymce.init({ inline: true, selector: '#myid', height: 100, menubar: true, }); $('#myid').on('blur', function(){ var temp = $('#myid').text(); console.log( temp ); // localStorage.setItem('tempTxt', temp ); }) 
 #myid { height: 100px; width: 400px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//cdn.tinymce.com/4/tinymce.min.js"></script> <link rel="stylesheet prefetch" href="//www.tinymce.com/css/codepen.min.css"> <link rel="stylesheet" type="text/css" id="u0" href="http://cdn.tinymce.com/4/skins/lightgray/skin.min.css"> <div id=myid>My custom text ..</div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM