tags:

views:

33

answers:

1

With CKEDITOR, when I use JS to get the contents of the Text Editor, I'm getting back:

<p>\u000a\u0009&nbsp;ad adad ad asd</p>\u000a

When I should have gotten:

<p>ad adad ad asd</p>

Any idea what's going on here?

The only difference that could be the cause is that I'm dynamically created textareas on load, and using a class to find the editor:

$('.guideItem-textarea').each(function(index, value){
    // ID of the textarea
    var targeteditor = $(this).attr('id');
    var targeteditorID = $(this).attr('id').replace('noteguide','');

    // Contents in the editor
    textareacontents = CKEDITOR.instances[targeteditor].getData();
});

Any ideas?

+1  A: 

Those strange characters are unicode control characters. The first one is a line feed, the seond is a tab. is the data in your example really the values in your question? Perhaps your prepopulated the text from some other source?

Suggested reading after you figure this out though: http://www.joelonsoftware.com/articles/Unicode.html

Brian
Brian thanks for the answer. The data is coming from CKEDITOR: textareacontents = CKEDITOR.instances.noteguide1.getData(); Is there a way to resolve this? Strip out all Unicode Control Characters?
AnApprentice
It also appears to only be happening in FIrefox, not safari
AnApprentice
I would look into where the data (i.e "ad adad ad asd" in your question) is being put into the ckeditor itself: If your doing something with jquery you might be experiencing some of the browser specific behavior described by text() in the docs: http://api.jquery.com/text/Since you have jQuery you might find some sort of regular expression you can execute to remove the control characters. Something like: http://stackoverflow.com/questions/846797/how-to-remove-space-and-restrict-special-chars-using-jquery
Brian