在当前位置TINYMCE IE9插入文本 [英] Insert Text at current position TINYMCE IE9

查看:152
本文介绍了在当前位置TINYMCE IE9插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在当前位置的tinyMce编辑器中插入文本. 它可以在Chrome,FF,Safari中完美运行,但在IE中,它始终从文本区域的顶部开始. 我目前正在执行以下操作:

How to insert text into a tinyMce edtitor at the current position. It works perfect in Chrome, FF, Safari, but in IE it always starts at the top of the textarea. I currently do the following:

tinyMCE.execCommand('mceInsertContent',false, 'blabla this is tekst');

我尝试了焦点,其他命令,没有用:(.

I tried with focus, other commands, nothing works :(.

推荐答案

感谢您的帮助,但没有任何帮助.我找到了自己的解决方案,并且觉得需要共享它,因为我只找到了过时的解决方案,这是行不通的:(.

Thanks for the help, but nothing worked. I found my own solution, and I felt like sharing this was needed, because I only found outdated solutions, that did not work :(.

解决方案:

在您的TinyMCE初始化中,添加以下代码:

In your TinyMCE init add following code:

    tinyMCE.init({
// General options
        elements: elementid,
        setup: function (ed) {
            ed.onKeyUp.add(function (ed, e) {
                actualCaretPositionBookmark = tinyMCE.activeEditor.selection.getBookmark();
            });
            ed.onClick.add(function (ed, e) {
                actualCaretPositionBookmark = tinyMCE.activeEditor.selection.getBookmark();
            }); 
        }

其中"actualCaretPositionBookmark"是javascript中的全局变量,您所有的javascript代码都可以访问

Where "actualCaretPositionBookmark" is a global variable in javascript that can be accesed by all your javascript code

然后,当您想通过javascript将文本添加到TinyMCE编辑器中时,添加以下代码:

Then when you want to add text into your TinyMCE editor via javascript, add following code:

                if (tinymce.isIE) {
                tinyMCE.activeEditor.selection.moveToBookmark(actualCaretPositionBookmark);
                tinyMCE.execCommand('mceInsertContent',false, 'My new text'); 

            }else {
                tinyMCE.execCommand('insertHTML',false, 'My new text'); 
            }

这篇关于在当前位置TINYMCE IE9插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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