我已经与CLEditor斗争了几个小时,试图实现一个简单的加法-添加target="_blank“选项复选框的可能性。守则是:
if (url != "") {
if ($("#blank").is(':checked')) {
editor.doc.execCommand("insertHTML", false, '<a href="' + url + '" target="_blank">' + selectedText(editor) + '</a>');
} else {
execCommand(editor, data.command, url, null, data.button);
}
// Reset the text, hide the popup and set focus
$text.val("http://");
hidePopups();
focus(editor);
}它可以很好地保存一个奇怪的故障--在添加了target="_blank“链接之后,我必须单击可编辑区域才能保存它。我可以在DOM中看到新添加的链接,但是--如果我不点击这个区域(任何地方)--我将无法保存它。
我将它添加到execCommand("insertHTML"..)而没有target="_blank“的链接是用execCommand(编辑器、data.command、url、null、data.button)插入的;并且没有这样的问题。
是什么导致了这样的问题呢?
没有part的整件事:https://jsfiddle.net/rzj0f334/
发布于 2016-12-08 04:51:10
奇怪的解决办法,不能认为是一个正确的答案,但无论如何。我所做的是:
if ($("#blank").is(':checked')) {
editor.doc.execCommand("insertHTML", false, '<a href="' + url + '" target="_blank">' + selectedText(editor) + '</a>');
// copy all the editor's iframe HTML and send it to textarea (queer solution but that's all I was able to come up with)
var iframe_content = $('#666').contents().find("body").html();
$('#input').html(iframe_content);
} else {
execCommand(editor, data.command, url, null, data.button);
}当然,这不是最好的方法,但至少它是有效的。不过,我很乐意找到一个更好的解决办法。
https://stackoverflow.com/questions/41012712
复制相似问题