2016-12-07 118 views
0

我一直在与CLEditor战斗了几个小时,试图实现一个简单的添加 - 添加target =“_ blank”选项复选框的可能性。 的代码是这样的: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); 

} 

它运作良好,保存一个奇怪的故障 - 我有一个目标=“_空白”的链接后,点击编辑区,将能够挽救它。 我可以在DOM中看到新添加的链接,但如果我不会点击该区域(任何地方),我将无法保存它。

我正在用execCommand(“insertHTML”..)添加它,而没有使用target =“_ blank”的链接正在用execCommand(editor,data.command,url,null,data.button)插入。并没有这样的问题。

什么可能导致此类问题?没有PHP部分

整个事情: https://jsfiddle.net/rzj0f334/

回答

0

怪异的解决办法,不能被视为一个恰当的答案,但无论如何。我做的是这样的:

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); 

    } 

绝对不是最好的方式来做到这一点,但至少它的工作原理。尽管如此,我会高兴地欣赏一个更好的解决方法。

相关问题