Tuesday, February 28, 2012

Adding Content To TinyMCE using javascript

If you ever want to add content to tinymce using javascipt. You can use the following code.

<script type="text/javascript">
window.onload = function () {
    tinyMCE.activeEditor.setContent('some html content here');
}
</script>

or using jQuery

<script type="text/javascript">
 $(function () {
      tinyMCE.activeEditor.setContent('some html content here');
 });
</script>

It requires you have only one tinyMCE editor. But if you have more you can use this.

tinyMCE.editors[index0].setContent('some html content here');
tinyMCE.editors[index1].setContent('some html content here');
tinyMCE.editors["nameOfEditor"].setContent('some html content here');

Hope this helps!