1

jQuery Text Editor: Remove pasted formatting that is not allowed

I am using the jQuery Text Editor, a wysiwyg editor to create rich formatted HTML in a textarea input.

I can initiate the editor in my javascript code and allow / disallow certain formatting options. But when I copy & paste text from somewhere else (Word, E-Mail client, etc.), it keeps all the formatting, even if I disallowed this particular formatting option in the editor.

Is there any smart way to strip all HTML formatting that I disallowed? Or even better can I tell the editor to strip disallowed formatting automatically that is pasted?

Guillermo
  • 197
  • 2
  • 4
  • 20

1 Answers1

0

Try this.

$(document).on("paste", ".jqte_editor", function(e) {

    e.preventDefault();
    var text = e.originalEvent.clipboardData.getData("text/plain");

    //Do required strip of HTML elements

    document.execCommand("insertText", false, text);
});
Tech Yogesh
  • 362
  • 1
  • 15
Ghost Rider
  • 127
  • 1
  • 1
  • 8