Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE - Writing plugin that insert content on top

I am trying to write a plugin for TinyMCE with a feature to add content to the beginning of the content. I know the following command which will insert content at the current location of the cursor. How do I force it to insert it at the beginning of the content?

tinyMCEPopup.editor.execCommand('mceInsertRawHTML', false, "halo world");
tinyMCEPopup.editor.execCommand('mceInsertContent', false, "halo world");
like image 914
TonyTakeshi Avatar asked Feb 01 '26 20:02

TonyTakeshi


1 Answers

For this you will need to set the cursor location to the beginning of the editor content. you may use the function setCursorLocation:

 ed.selection.setCursorLocation(ed.getBody().firstChild, 0); // node to set the cursor to, second param is offset
like image 88
Thariama Avatar answered Feb 04 '26 11:02

Thariama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!