How to insert text into a tinyMce edtitor at the current position. It works perfect in Chrome, FF, Safari, but in IE it always starts at the top of the textarea. I currently do the following:
tinyMCE.execCommand('mceInsertContent',false, 'blabla this is tekst');
I tried with focus, other commands, nothing works :(.
Thanks for the help, but nothing worked. I found my own solution, and I felt like sharing this was needed, because I only found outdated solutions, that did not work :(.
The solution:
In your TinyMCE init add following code:
tinyMCE.init({
// General options
elements: elementid,
setup: function (ed) {
ed.onKeyUp.add(function (ed, e) {
actualCaretPositionBookmark = tinyMCE.activeEditor.selection.getBookmark();
});
ed.onClick.add(function (ed, e) {
actualCaretPositionBookmark = tinyMCE.activeEditor.selection.getBookmark();
});
}
Where "actualCaretPositionBookmark" is a global variable in javascript that can be accesed by all your javascript code
Then when you want to add text into your TinyMCE editor via javascript, add following code:
if (tinymce.isIE) {
tinyMCE.activeEditor.selection.moveToBookmark(actualCaretPositionBookmark);
tinyMCE.execCommand('mceInsertContent',false, 'My new text');
}else {
tinyMCE.execCommand('insertHTML',false, 'My new text');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With