[英]execCommand behavior in IE : CLEditor image overwrite problem
I am using CLEditor in my site and I am facing a problem when using it with IE. 我在网站上使用CLEditor ,与IE一起使用时遇到问题。 The problem is: When you insert image and place it in the editor then insert another image , it will overwrite the prevoius one. 问题是:当您插入图像并将其放置在编辑器中,然后插入另一图像时,它将覆盖prevoius图像。 With Firefox it will place the new one beside the prevoius one. 借助Firefox,它将把新版本放置在prevoius版本旁边。 I contacted the CLEditor and he told me this is a browser sprecific issue. 我联系了CLEditor,他告诉我这是浏览器的重要问题。 He adivse me to make a work around by checking for IE then collapse the current range to its end using TextRange.collapse() method after the image have been inserted. 他通过检查IE来使我变通,然后在插入图像后使用TextRange.collapse()方法将当前范围折叠到其末端。 I tried to make this soultion but I am not expert with Javascript to make it works. 我试图使这种灵魂化,但我不是Java专家,无法使其发挥作用。 I need your help to make it working. 我需要您的帮助才能使其正常运行。
This is the code for inserting the image to the editor area: 这是用于将图像插入编辑器区域的代码:
.bind(CLICK, function() {
// Insert the image or link if a url was entered
var $text = $popup.find(":text"),
url = $.trim($text.val());
if (url !== "")
execCommand(editor, data.command, url, null, data.button);
// Reset the text, hide the popup and set focus
$text.val("http://");
hidePopups();
focus(editor);
});
This is the solution for this problem. 这是解决此问题的方法。 It take three days to solve this because I am not JavaScript expert. 解决此问题需要三天,因为我不是JavaScript专家。 I hope this will help. 我希望这将有所帮助。
.bind(CLICK, function() {
// Insert the image or link if a url was entered
var $text = $popup.find(":text"),
url = $.trim($text.val());
if (url !== "")
execCommand(editor, data.command, url, null, data.button);
// Reset the text, hide the popup and set focus
$text.val("http://");
hidePopups();
if ($.browser.msie) {
var editorvalue=editor.$frame[0].contentWindow;
var pos = editorvalue.document.body.innerHTML.length;
var textRange = editorvalue.document.body.createTextRange();
textRange.collapse(true);
textRange.moveEnd("character", pos);
textRange.moveStart("character", pos);
textRange.select();
}
focus(editor);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.