How to force plaintext insertion on paste in tiny_mce

Several clients of ours seem to type the text for their websites in a Word document fires and copy them afterwards in tiny_mce. Apparently tiny_mce copies the layout from word or any other program so the layout in your website gets messed up. I found a solution for this. You have to enforce pasting as plaintext which removes all markup when you paste something within tiny_mce.

copy these lines within your tinyMCE.init function where you instantiate tiny_mce:

//force text to be pasted as plaintext
setup: function(ed) {
ed.onPaste.add( function(ed, e, o) {
ed.execCommand('mcePasteText', true);
return tinymce.dom.Event.cancel(e);
});
},

When you paste something within tiny_mce a popup dialogue will appear. After insertion all markup tags will be removed, accept line-breaks.

Comments

Posted on 19-06 by lourpopyivy

Thanks for blog post. It's very good stuff. I love to browse www.stevendobbelaere.be.

Posted on 03-11 by Pieter

This is just what I was looking for, it turns out to be not so simple to force a plain-text paste that works across all browsers. One thing I found is that you need to have the following configuration option in your tinyMCE init: paste_auto_cleanup_on_paste : false, Without this, if you use the posted code in internet explorer, several paste windows will popup!

Leave a comment