1

How to insert custom text to JCE v. 2.3.4.4 using javascript?

I have opened the page source and saw that the editor is an iframe. Text is in <body id="tinymce">.

I was trying something like:

$("body#tinymce").html("mytext");

but it doesn't work. Of course, it is executed on domReady.

  • is that element is accessible through $("body#tinymce") selector?? – subashbasnet8 Jan 26 '15 at 10:23
1

I have found a solution.

var id = "yourTextAreaId";
var tmce_el = tinyMCE.get(id);
if (tmce_el != undefined)
{
    tmce_el.execCommand('mceSetContent', false, value);
}
else
{
    document.getElementById(id).innerHTML = value;
    document.getElementById(id).value = value;
}
  • You may accepted your own answer to mark your isssue resolved. – mickmackusa May 27 at 13:32
0

I think the better way is to use the Joomla.editors.instances

You will be able to validate that it has the textAreaId loaded and then update with the setValue method.

if (Joomla.editors.instances.hasOwnProperty('yourTextAreaId')) {
    Joomla.editors.instances['yourTextAreaId'].setValue(value);
} else {
    // do you custom script as fail-safe
}

I have tested this with codemirror, tinyMCE, none (when no editor is set) and it works very well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.