Stack OverflowAbout
Products
For Teams
Log in
Sign up
Home
Questions
Tags
Users
Companies
LABS
DiscussionsNEW
COLLECTIVES
Explore Collectives
TEAMS
Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. Create a free Team Why Teams?
How to make tinymce paste in plain text by default
Ask Question
Asked 13 years, 10 months ago
Modified 4 years, 4 months ago
Viewed 99k times
110
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 "paste as text" button.
Any Ideas of how to implement that? or how to enable the "paste as text" button automatically?
Thank you
javascript
jquery
tinymce
Share
Improve this question
Follow
edited Apr 28, 2010 at 3:11
asked Apr 23, 2010 at 2:03
CodeOverload47.7k5656 gold badges132132 silver badges219219 bronze badges
Add a comment
11 Answers
Sorted by:
Highest score (default)
Trending (recent votes count more)
Date modified (newest first)
Date created (oldest first)
172
For the tinyMCE 3X or 4X things have change a little. now you can do this and it works fine.
tinymce.init({
plugins: "paste",
paste_as_text: true
});
Share
Improve this answer
Follow
edited May 5, 2014 at 11:09
answered Jul 2, 2013 at 9:24
Paulo Almeida2,16922 gold badges1717 silver badges1919 bronze badges
5
Yes,the other approaches did not work but this does. – Tim
Apr 2, 2014 at 17:59
2
@Tim The approach shown in the answer of this question is specific TinyMCE 3.x. If you're using TinyMCE 4 or bigger, the approach in this answer will do. – Leonardo Montenegro
Apr 30, 2014 at 20:53
There is a plugin or option for just about anything in TinyMCE.. no wonder it is the best! – supersan
Feb 22, 2017 at 19:32
1
Thank you for the solution, but this actually mean that I've to remember to edit the configuration file every time the plugins got updated? – Mike
Jan 16, 2018 at 13:06
Add a comment
86
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;
});
}
....
})
Share
Improve this answer
Follow
answered Aug 27, 2010 at 8:56
Dariusz Lyson96911 gold badge66 silver badges33 bronze badges
11
For what it worth, I think your solution is better than the selected answer. – arikfr
Dec 9, 2010 at 18:58
@Dariusz Lyson , any suggestions on how to persist the tinyMCE formatted string using a form ? : stackoverflow.com/questions/17247900/… – codeObserver
Jun 23, 2013 at 0:36
10
I get a javascript error, that the onInit property of ed is undefined. Unable to get property 'add' of undefined or null reference – Tim
Apr 2, 2014 at 17:45
Add a comment
61
+400
EDIT: this solution is for version 3.x, for 4.x version read the answer from @Paulo Neves
The problem is that Paste plugin automatically resets plain text paste on every paste. So all we need to do - set it back. The following code should help.
tinyMCE.init({
...
oninit : "setPlainText",
plugins : "paste"
....
});
The definition of setPlainText
function setPlainText() {
var ed = tinyMCE.get('elm1');
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;
});
}
}
So now it always will be plain.
Share
Improve this answer
Follow
edited Oct 14, 2015 at 8:36
zeldi4,86333 gold badges1919 silver badges1818 bronze badges
answered Apr 28, 2010 at 6:14
er-v4,44533 gold badges3030 silver badges3737 bronze badges
I thtink it's becouse of absent paste plugin I've created working example - take a look 92.248.232.12/tinymce/examples/simple.html tinyMCE.init({ ... oninit : "setPlainText", plugins : "paste" .... }); – er-v
Apr 29, 2010 at 9:12
5
Great answer, although I've found I get JS errors relating to the definition of "ed". This was simple to fix by just removing the tinyMCE.get("elm1") line and putting ed as the first parameter of the setPlainText method: e.g. "function setPlainText(ed) { ...". – drmonkeyninja
Feb 21, 2012 at 11:12
8
In later versions of tinymce, some options were added to take care of this. paste_text_sticky_default: true and paste_text_sticky: true in your config should do the trick. (I'm using 3.5.0.1) – Greg
Jan 24, 2013 at 2:15
@er-v any suggestions on how to persist the tinyMCE formatted string using a form : stackoverflow.com/questions/17247900/… – codeObserver
Jun 23, 2013 at 0:34
13
Just tried .init({ plugins: ["paste"], paste_as_text: true }), and it works like a charm with TinyMCE 4.1, without the need of an additional function. – Rémi Breton
May 19, 2015 at 18:37
Show 4 more comments
38
Just ran into this one myself and discovered that as of TinyMCE 3.4.2 you can simply:
paste_text_sticky: true,
paste_text_sticky_default: true
...which was nice.
Share
Improve this answer
Follow



