如何在tinymce中的光标位置插入图像 [英] How To insert an image at cursor position in tinymce

查看:581
本文介绍了如何在tinymce中的光标位置插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来获取tinymce的内容.

I am using following codes to fetch the conent of tinymce.

tinymce_content=tinyMCE.get('txt_area_id').getContent();
updated_content=tinymce_content+"<img src="sample.jpg">";

通过使用以上代码,我将图像插入tinymce内容内.

By using above codes i am inserting image inside tinymce content.

问题:如何在tinymce内部的光标位置插入图像(即,如何预测光标位置并拆分内容以在获取的内容之间插入图像.

Question: How to insert image in the cursor position inside tinymce (ie) How to predict cursor position and split the content to insert image between fetched content.

预先感谢

推荐答案

这将在tinymce编辑器中的所选位置(光标位置)插入一个图像节点

This will insert an image node at the selected spot (cursor position) in a tinymce editor

var ed = tinyMCE.get('txt_area_id');                // get editor instance
var range = ed.selection.getRng();                  // get range
var newNode = ed.getDoc().createElement ( "img" );  // create img node
newNode.src="sample.jpg";                           // add src attribute
range.insertNode(newNode);                          // insert Node

这篇关于如何在tinymce中的光标位置插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆