【发布时间】:2012-06-26 09:51:29
【问题描述】:
我正在尝试在当前光标位置插入一些内容或替换 TinyMCE 编辑器实例中的选定内容。我正在使用这个:
tinyMCEPopup.editor.selection.setContent(content);
content 是我要插入的 HTML 字符串。
它在 Firefox、Opera 和 Chrome 上运行良好,但在 IE 中无法运行。相反,它在编辑器的开头插入内容,而不是选择。我也试过:
tinyMCEPopup.execCommand('mceInsertContent', false, content);
同样,IE 中的行为相同。用于插入特殊字符的 TinyMCE 代码使用了上面的函数并且有效!我已经尝试在我的插件中复制它,但仍然没有乐趣......
function insertChar(chr) {
tinyMCEPopup.execCommand('mceInsertContent', false, '&#' + chr + ';');
// Refocus in window
if (tinyMCEPopup.isWindow)
window.focus();
tinyMCEPopup.editor.focus();
tinyMCEPopup.close();
}
更新:
仍然无法在 IE 中运行,Opera 甚至没有在工具栏中显示我的插件按钮(尽管这可能是一个单独的问题)!我现在也尝试了 jQuery 插件,让编辑器加载,但无法在其上调用 mceInsertContent 方法,即使使用这个:
$('#my-editor-id').tinymce().execCommand('mceInsertContent', false, content);
出现错误:“对象没有方法:tinymce” - 也许我不能从弹出窗口中调用它?!
【问题讨论】:
-
我的情况也一样。使用 IE>=8 不起作用!我找到了这个link。那家伙解决了它(可能使用jQuery插件)。使用 JS 代码,我确认它不起作用。
-
谢谢大卫。花了很长时间看这个,几乎放弃它。刚刚用我对 jQuery 插件的经验更新了我的问题。我很确定 IE 或 TinyMCE 都是垃圾,只是还不确定哪个 :) 不过我倾向于 IE!
-
@greg84 也许我不能从弹出窗口中调用它?! Tinymce 情绪插件(emotions.js)使用相同的 tinyMCEPopup.execCommand('mceInsertContent', false,文件);用于在光标位置插入图标,并且适用于所有浏览器,包括 IE ...