【问题标题】:CLEditor - adding target="_blank"CLEditor - 添加 target="_blank"
【发布时间】:2016-12-07 08:36:18
【问题描述】:

我已经与 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);

 }

它可以很好地保存一个奇怪的故障 - 我必须在添加 WITH target="_blank" 链接后单击可编辑区域才能保存它。 我可以在 DOM 中看到新添加的链接,但如果我不点击该区域(任何地方),我将无法保存它。

我正在使用 execCommand("insertHTML"..) 添加它,而没有 target="_blank" 的链接正在使用 execCommand(editor, data.command, url, null, data.button);并且没有这样的问题。

什么会导致这样的问题?

没有 PHP 部分的整个事情: https://jsfiddle.net/rzj0f334/

【问题讨论】:

    标签: jquery execcommand cleditor


    【解决方案1】:

    奇怪的解决方法不能被视为正确的答案,但无论如何。我做的是这样的:

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

    绝对不是最好的方法,但至少它有效。不过,我很高兴有更好的解决方法。

    【讨论】:

      猜你喜欢
      • 2013-06-21
      • 2023-04-03
      • 1970-01-01
      • 2021-01-08
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-25
      相关资源
      最近更新 更多