1

Topic: How can I insert some data into Tinymce?

I get tinymce data with a get method:

ed=tinyMCE.get('myid');
ed.getContent

how can I insert some data into tinymce editor?

2

Re: How can I insert some data into Tinymce?

hoomijoon wrote:

I get tinymce data with a get method:

ed=tinyMCE.get('myid');
ed.getContent

how can I insert some data into tinymce editor?

This inserts "Hello there" text at the cursor:

    var ed = tinymce.activeEditor;
    var text = 'Hello there';
    ed.execCommand('mceInsertContent', false, text);

This inserts "Hello there" (bolded HTML) at the cursor:

    var ed = tinymce.activeEditor;
    var html = '<p style="font-weight:bold;">Hello there</p>';
    ed.execCommand('mceInsertContent', false, html);

Hope this helps.

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

3

Re: How can I insert some data into Tinymce?

Thanks, but it doesnt work!!

4

Re: How can I insert some data into Tinymce?

hoomijoon wrote:

Thanks, but it doesnt work!!

Strange. It should work. Try this:

setTimeout(function() {
    alert(tinymce.activeEditor);
}, 5000);

It should pop up after 5 seconds with the message "[object Object]". If it says "undefined", then you are doing something wrong either with the editor or else your Javascript isn't "reaching" the editor.

Let me know what you get and we can troubleshoot from there.

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

5

Re: How can I insert some data into Tinymce?

hoomijoon wrote:

Thanks, but it doesnt work!!

Another thought... do you have the code written correctly? CASE is important. For example,

"tinymce.activeeditor" is wrong. It must be "tinymce.activeEditor".

Javascript is case sensitive.

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

6

Re: How can I insert some data into Tinymce?

Thank you so much, my problem solved. I have another question: How ca I clear all text inside the editor?

7

Re: How can I insert some data into Tinymce?

I have another question. does tinymce have a ruler like microsoft word?

8

Re: How can I insert some data into Tinymce?

hoomijoon wrote:

Thank you so much, my problem solved. I have another question: How ca I clear all text inside the editor?

Use the "New Document" button or this code:

    ed.execCommand('mceSetContent', false, '');

(in fact, that is the code that the "newdocument" button uses!)

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov

9

Re: How can I insert some data into Tinymce?

hoomijoon wrote:

I have another question. does tinymce have a ruler like microsoft word?

As far as I know... the answer is "NO". I may be wrong though (someone chime in).

"Anything that is complex is not useful and anything that is useful is simple. This has been my whole life's motto." -- Mikhail T. Kalashnikov