我在我的网站上使用了CLEditor(CLEditor)并且它运行良好只是我希望能够设置到_blank的链接目标但我无法弄明白,即使在查看源代码时也是如此
是否有人可以帮助我使编辑器建立的链接具有_blank
的目标由于
答案 0 :(得分:2)
$('textarea').cleditor({
updateTextArea: function(html) {
var e = $('<div>').append(html);
e.find('a[href]').attr('target', '_blank');
return e.html();
}
});
答案 1 :(得分:1)
您可以将属性添加到每个链接:
$("#cleeditor iframe").contents().find("a[href]").attr("target", "_blank");
答案 2 :(得分:1)
(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);
只需在函数execCommand中添加此按钮或cleditor replace:
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);
}
}