Googled it thousands of times, No one gives a complete solution of how to make Tinymce paste in plain text by default and strip out any formatting without clicking the \"pas
If you cannot use or do not want to use a plug-in for whatever reason, you can create your own "paste as plain text" callback function like so:
tinyMCE.init({
// ...,
setup: function (editor) {
// Listen for paste event, add "Paste as plain text" callback
editor.onPaste.add(function (editor, e) {
// Prevent default paste behavior
e.preventDefault();
// Check for clipboard data in various places for cross-browser compatibility.
// Get that data as text.
var content = ((e.originalEvent || e).clipboardData || window.clipboardData).getData('Text');
// Let TinyMCE do the heavy lifting for inserting that content into the editor.
editor.execCommand('mceInsertContent', false, content);
});
}
});
Note: This was created for TinyMCE 3.5.x. Compatibility may vary by version.
I did as follows:
var pastePlainText = function() {
// No need to pass in an ID, instead fetch the first tinyMCE instance
var ed = tinyMCE.get(0);
ed.pasteAsPlainText = true;
//adding handlers crossbrowser
if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) {
ed.onKeyDown.add(function (ed, e) {
if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
ed.pasteAsPlainText = true;
});
} else {
ed.onPaste.addToTop(function (ed, e) {
ed.pasteAsPlainText = true;
});
}
};
And then:
tinyMCE.init({
// ...
plugins: "paste",
oninit: pastePlainText // Note, without "
// ...
})
I have solved this problem with this code
tinyMCE.init({
...
plugins : "paste",
paste_text_sticky : true,
setup : function(ed) {
ed.onInit.add(function(ed) {
ed.pasteAsPlainText = true;
});
}
....
})
Isn't it better to use:
var ed = tinyMCE.activeEditor;
instead of:
var ed = tinyMCE.get('elm1');
I think the easiest way would be this:
tinymce.init({
...
paste_as_text: true,
plugins: "paste",
...
});