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
  • 327
  • 2
  • 6
  • 20

2 Answers2

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
  • 427
  • 4
  • 18
Ghost Rider
  • 161
  • 1
  • 1
  • 10
0
$(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);
});

The above code I have tried but when I copied it from excel to jQuery richtext the formatting was lost.

Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36