开发者

how to get html from CKEditor? [duplicate]

This question already has answers here: Get formatted HTML from CKEditor (12 answers) Closed 10 years ago.

I'm using CKEditor in my web app, but I don't know how to get html content from it.http://cksource.com/ckeditor I searched online found one said using getData() method, but there is no getData() method after typing dot after the开发者_Go百科 controler. Can anyone give me a sample code to get html from CKEditor controller? Thank you in advance.


To get htmlData from editor you should use the code snippet bellow:

var htmldata = CKEDITOR.instances.Editor.document.getBody().getHtml();

If this solution won't work, check if you have BBCode plugins installed.


getData() is part of the javascript API. It seems that you are trying to do it at the server side, so you should check the specific API of whatever wrapper you are using, or just check the value in the form posted data.


Not sure how you're implementing usage of the CKEditor.

If you're replacing a textarea using CKEDITOR.replace( 'NameOfTextarea', this should work:

CKEDITOR.instances.NameOfTextarea.on( 'instanceReady', function( instanceReadyEventObj )
{
  var editorInstanceData = CKEDITOR.instances.NameOfTextarea.getData();
  alert( editorInstanceData );
});

Replace "NameOfTextarea" with the name of your textarea, it's used to name the editor instance.

It's a good idea to put it inside the "on instanceReady" function so you don't get an undefined error.

Joe

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜