Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript tinymce.selection.setContent在IE中文本区域的开头插入文本_Javascript_Jquery_Internet Explorer_Iframe_Tinymce - Fatal编程技术网

Javascript tinymce.selection.setContent在IE中文本区域的开头插入文本

Javascript tinymce.selection.setContent在IE中文本区域的开头插入文本,javascript,jquery,internet-explorer,iframe,tinymce,Javascript,Jquery,Internet Explorer,Iframe,Tinymce,我已经为tinyMCE创建了一个插件,使用MathJax将数学公式插入编辑器中。 这个插件在iframe中打开一个弹出窗口(使用jQuery),然后启动一个触发事件,在tinyMCE活动编辑器中插入输入的公式 我的代码在Chrome&Firefox中正常工作(创建插入文本区域插入符号位置的pre),但在IE中,文本插入文本区域的开头 我使用的setContent方法如下: tinyMCE.activeEditor.selection.setContent(text to insert, {for

我已经为tinyMCE创建了一个插件,使用MathJax将数学公式插入编辑器中。 这个插件在iframe中打开一个弹出窗口(使用jQuery),然后启动一个触发事件,在tinyMCE活动编辑器中插入输入的公式

我的代码在Chrome&Firefox中正常工作(创建插入文本区域插入符号位置的
pre
),但在IE中,文本插入文本区域的开头

我使用的setContent方法如下:

tinyMCE.activeEditor.selection.setContent(text to insert, {format: 'bbcode'});

var myField = tinyMCE.get("SMSBody");

    //IE support
   if (document.selection) {

         myField.focus();
         sel = document.selection.createRange();
         sel.text = fieldName;
    }
else if (document.getSelection) {

         tinyMCE.activeEditor.selection.setContent(fieldName);
         myField.focus();
    }
var sel = tinyMCE.activeEditor.selection;
sel.setContent('<span id="_math_marker">&nbsp;</span>');
在插入之前,我尝试使用
ed.focus()
,在StackOverflow中找到了其他建议,但没有任何效果

此外,我试图在打开弹出窗口之前保存插入符号位置,并在插入时恢复它,但无论如何都不起作用

有什么想法吗


提前谢谢。

试试这样的方法:

tinyMCE.activeEditor.selection.setContent(text to insert, {format: 'bbcode'});

var myField = tinyMCE.get("SMSBody");

    //IE support
   if (document.selection) {

         myField.focus();
         sel = document.selection.createRange();
         sel.text = fieldName;
    }
else if (document.getSelection) {

         tinyMCE.activeEditor.selection.setContent(fieldName);
         myField.focus();
    }
var sel = tinyMCE.activeEditor.selection;
sel.setContent('<span id="_math_marker">&nbsp;</span>');

希望它对您有用。

嗨,我使用了一个名为jCaret的jQuery插件来解决这种情况。 在大多数常用的浏览器(即7、8、9以及兼容模式)中都能很好地工作

请看下面链接中给出的示例

谢谢

已解决:

我知道这不是最优雅的解决方案,但对我来说很有效

在打开弹出窗口之前,我插入一个带有特定ID的“范围”,如下所示:

tinyMCE.activeEditor.selection.setContent(text to insert, {format: 'bbcode'});

var myField = tinyMCE.get("SMSBody");

    //IE support
   if (document.selection) {

         myField.focus();
         sel = document.selection.createRange();
         sel.text = fieldName;
    }
else if (document.getSelection) {

         tinyMCE.activeEditor.selection.setContent(fieldName);
         myField.focus();
    }
var sel = tinyMCE.activeEditor.selection;
sel.setContent('<span id="_math_marker">&nbsp;</span>');
这适用于所有浏览器!如果弹出窗口关闭,请记住删除范围,不要插入任何内容,以免在编辑器中留下垃圾


:-)

只需删除.selection部分,您的代码应该如下所示


tinyMCE.activeEditor.setContent(要插入的文本,{format:'bbcode'})

在IE8中无法获取活动编辑器,所以需要聚焦,所以使用

tinyMCE.activeEditor.focus()


希望它对您有效。

不起作用:(现在我正在尝试在打开弹出窗口之前保存该职位。我将尽快更新。谢谢:)我会参考您的建议。谢谢