首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在CLEditor中更改锚标签

在CLEditor中更改锚标签
EN

Stack Overflow用户
提问于 2011-03-22 00:13:02
回答 3查看 2.5K关注 0票数 4

我正在我的网站(CLEditor)上使用CLEditor,它工作得很好,只是我希望能够设置到_blank的链接目标,但我无法弄清楚,即使是在查看源代码时也是如此。

有没有人可以帮我把编辑出来的链接设为_blank

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-03-22 00:26:46

您可以将属性添加到每个链接:

代码语言:javascript
复制
$("#cleeditor iframe").contents().find("a[href]").attr("target", "_blank");
票数 1
EN

Stack Overflow用户

发布于 2012-04-28 12:10:25

代码语言:javascript
复制
$('textarea').cleditor({
  updateTextArea: function(html) {
    var e = $('<div>').append(html);
    e.find('a[href]').attr('target', '_blank');
    return e.html();
  }
}); 
票数 2
EN

Stack Overflow用户

发布于 2012-03-15 01:07:27

代码语言:javascript
复制
(function($) {

// Define the lien button
$.cleditor.buttons.lien = {
    name: "lien",
    image: "lien.gif",
    title: "Add link",
    command: "inserthtml",
    popupName: "Lien",
    popupClass: "cleditorPrompt",
    popupContent: 'Enter URL:<br><input type=text value="http://" size=35><br><input type=button value="submit">',
    buttonClick: lienClick
};

// Add the button to the default controls before the bold button
$.cleditor.defaultOptions.controls = $.cleditor.defaultOptions.controls
.replace("link", "lien link");

// Handle the lien button click event
function lienClick(e, data) {

    // Get the editor
    var editor = data.editor;

    if (editor.selectedText() === "") {
        editor.showMessage("A selection is required when inserting a link.");             
        return false;
    }

    // Wire up the submit button click event
    $(data.popup).children(":button")
    .unbind("click")
    .bind("click", function(e) {

        // Get the entered name
        var url = $(data.popup).find(":text").val();     
        var value = '<a href="' + url + '" target="_blank">' + editor.selectedText() + '</a>'
        var success = editor.doc.execCommand("insertHTML", 0, value || null)

        if (!success){
            editor.showMessage("Error executing the insertHTML command.");
        }
        // Hide the popup and set focus back to the editor
        editor.hidePopups();
        editor.focus();

    });      
}     
})(jQuery);

只需在function execCommand中添加此按钮或在清除程序中替换:

代码语言:javascript
复制
try { 
      if(command.toLowerCase() == "createlink"){
        value = '<a href="' + value + '" target="_blank">' + getRange(editor) + '</a>'
        success = editor.doc.execCommand("insertHTML", 0, value || null);
      }else{
         success = editor.doc.execCommand(command, 0, value || null); 
      }
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5380393

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档