Insert an image into a tinymce editor

心不动则不痛 提交于 2019-12-12 08:27:55

问题


I have a tinymce text box on my html page. Under this text box I have a table with my file system in which I can navigate to locate my images. I would like to be able to click on an image in this table and have it inserted in the timymce text box. How might I go about doing this?


回答1:


I've used the command

tinyMCE.execCommand('mceInsertContent', false, '<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');

to insert the image in tinyMCE after extracting the URL from the image's src.

Note that you need to pass the CSS style of the image to tinyMCE in the command.

EDIT: for Tiny MCE 4.x, the insert image code can be simplified to: tinymce.activeEditor.insertContent('<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');

Here's the demo.




回答2:


The fiddle from user2314737 is broken. So I combine with Fei Hap Lee's solution to have working one.

        tinymce.activeEditor.insertContent('<img alt="Smiley face" height="42" width="42" src="' + sr + '"/>');

fiddle



来源:https://stackoverflow.com/questions/21854798/insert-an-image-into-a-tinymce-editor

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