Appending a string to a tinyMCE instance

我只是一个虾纸丫 提交于 2019-12-11 12:24:38

问题


I need to append a string (an img tag) to a tinyMCE editor instance.

I was doing it like this:

$("#textboxhiddenbytinymce").append( string );
tinyMCE.triggerSave();

with no luck. I was wondering if:

There is a direct method for adding an arbitrary string (I need complete control over it) to an instance of tinyMCE I understand that the way I'm doing it is wrong since tinyMCE works indipendently to the "original" textarea.

Thank you very much!


回答1:


The only way this will work is if you use the jQuery Plugin version. Luckily it's easy to convert an existing tinyMCE.init block to use jQuery:

$().ready(function () {
    $('textarea#tinymce').tinymce({
        script_url: 'tinymce/jscripts/tiny_mce/tiny_mce.js',
        // and all your existing config
});

Then you can access the $('textarea#tinymce') object and edit it as you would a normal element.

Hope this answer is still helpful to someone a year after the question was posted!




回答2:


Current versions of TinyMCE (version 4 at the moment) put their content in an iframe. After you find the id of that iframe, something similar to the following can be used:

var id_of_iframe = '';
$('#' + id_of_iframe).contents().find('#tinymce').append(string);


来源:https://stackoverflow.com/questions/2787684/appending-a-string-to-a-tinymce-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!