最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Programmatically retrieve content from WYSIHTML5 editor - Stack Overflow

programmeradmin0浏览0评论

How do I programmatically retrieve content from a WYSIHTML5 editor? Suppose the editor is instantiated as this:

var editor = new wysihtml5.Editor
(
   $(this.el).find('textarea').get(0),
   {
      toolbar:      "toolbar",
      parserRules:  wysihtml5ParserRules
   }
);

i would like to get the editor's content on blur event

editor.on
(
   "blur",
   function()
   {
      //what here?
   }
);

How do I programmatically retrieve content from a WYSIHTML5 editor? Suppose the editor is instantiated as this:

var editor = new wysihtml5.Editor
(
   $(this.el).find('textarea').get(0),
   {
      toolbar:      "toolbar",
      parserRules:  wysihtml5ParserRules
   }
);

i would like to get the editor's content on blur event

editor.on
(
   "blur",
   function()
   {
      //what here?
   }
);
Share Improve this question edited Jan 22, 2019 at 6:08 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked Jun 11, 2012 at 19:07 DalenDalen 9,0064 gold badges49 silver badges53 bronze badges 1
  • You can either look at the docs of that editor or retrieive it from rendered output of it by inspecting through console. – Sarfraz Commented Jun 11, 2012 at 19:09
Add a comment  | 

2 Answers 2

Reset to default 11

It's much better to use the API editor.getValue()

(@dalen mentioned this in the comment above)

Here is how (using jQuery here):

$('iframe').contents().find('.wysihtml5-editor').html();

To find text instead, use text() instead of html().

FYI:

  • I jQuerified this demo page of it using jQueryify bookmarklet
  • Entered some text in editor
  • typed above code at console and output was entered text

In your application, you won't need the jQueryify bookmarklet, I used it to inject jQuery on that demo page so that I could use it to get the value of editor.


Having said that, there normally should be some built-in method in that editor to get current value you should look at the docs :)

发布评论

评论列表(0)

  1. 暂无评论