Programmatically retrieve content from WYSIHTML5 editor

拈花ヽ惹草 提交于 2019-12-10 14:59:16

问题


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?
   }
);

回答1:


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

(@dalen mentioned this in the comment above)




回答2:


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 :)



来源:https://stackoverflow.com/questions/10986054/programmatically-retrieve-content-from-wysihtml5-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!