简体   繁体   English

CKEDITOR添加图片

[英]CKEDITOR add image

I want to add a image to the content of a textarea (replaced by CKEDITOR). 我想将图像添加到textarea的内容中(由CKEDITOR代替)。

What I have is a script, that takes the image uploaded, and transforms it to BASE64 (after downsizing it). 我所拥有的是一个脚本,该脚本将上载的图像转换为BASE64(缩小尺寸后)。

And I know, that the textarea of CKEDITOR is able to show images (as there is the possibility to insert images via url). 而且我知道,CKEDITOR的textarea能够显示图像(因为可以通过url插入图像)。 But actually nothing I tried is working. 但是实际上我没有尝试过。

So I have a textarea with the ID editor and I replace it by var editor = CKEDITOR.replace('editor'); 因此,我使用ID editor了一个文本区域,并用var editor = CKEDITOR.replace('editor');替换了它var editor = CKEDITOR.replace('editor'); .

What I tried is $('#editor').append('<img src="data:image/jpeg;base64,.........) , not working. I also tried iit with editor.insertHTML() but that doesn't work as well.... 我试过的是$('#editor').append('<img src="data:image/jpeg;base64,.........) ,不起作用。我还尝试了用editor.insertHTML() iit。 editor.insertHTML()但效果不佳...。

What I tried now, is to insert the base64-string in the url input of CKEDITOR (when adding an image), that worked. 我现在尝试的是在CKEDITOR的url输入中插入base64字符串(添加图像时),此方法有效。 So does anybody know how I can do that? 那么有人知道我该怎么做吗? Either by just appending an image with the base64 as src, or by inserting the base64-string as url for the built in image upload function. 可以通过仅将base64附加为src来添加图像,或者通过将base64字符串作为url插入内置图像上载功能来实现。

Figured out how to do it: 想通了怎么做:

CKEDITOR.instances.editor.insertHtml('<img src="' + base64string + '">'); .

This did the trick for me, so actually working with insertHtml, but by acccessing CKEDITOR.instances.editor, and not by the var, declared when replacing the editor. 这对我来说是成功的诀窍,因此实际上可以使用insertHtml,但是要在替换编辑器时声明CKEDITOR.instances.editor,而不是由var声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM