I'm trying to insert some content at the current cursor position or replace the selected content in a TinyMCE editor instance. I'm using this:
tinyMCEPopup.editor.selection.setContent(content);
Where content is a string of HTML that I want to insert.
It works great on Firefox, Opera and Chrome, but won't work in IE. Instead it inserts content at the beginning of the editor, instead of the selection. I've also tried:
tinyMCEPopup.execCommand('mceInsertContent', false, content);
Again, same behavior in IE. The TinyMCE code for inserting special characters uses the function above and that works! I've tried replicating it in my plugin and still no joy...
function insertChar(chr) {
tinyMCEPopup.execCommand('mceInsertContent', false, '&#' + chr + ';');
// Refocus in window
if (tinyMCEPopup.isWindow)
window.focus();
tinyMCEPopup.editor.focus();
tinyMCEPopup.close();
}
UPDATE:
Still not working in IE, Opera doesn't even show my plugin's button in the toolbar (although that's probably a separate issue)! I've now also tried the jQuery plugin, got the editors to load, but couldn't call the mceInsertContent method on it, even using this:
$('#my-editor-id').tinymce().execCommand('mceInsertContent', false, content);
Got an error: "object has no method: tinymce" - maybe I can't call that from a popup?!