gpt4 book ai didi

ckeditor - 在 CKEditor 中插入一个链接

转载 作者:行者123 更新时间:2023-12-04 02:48:32 26 4
gpt4 key购买 nike

我正在尝试使用以下行将链接插入到 CKEditor 的实例中:-

CKEDITOR.instances.CKInstance.insertHtml('<a href="http://www.example.com">My Text</a>');

但发生的只是插入“MyText”时没有链接。有人知道如何正确插入链接吗?

附言。我知道 CKEditor 带有一个插入链接的插件,但我正在做我自己的一个

谢谢沙祖

最佳答案

我猜您使用的是 CKEditor 4.1 或更新版本。由于您不使用官方链接插件,因此您的编辑器会丢弃所有 <a>标签。您需要正确配置 Allowed Content Filter所以你的编辑接受 <a>再次标记回来。

您可以在定义命令时执行此操作,如下所示:

// Assuming you want a dialog-driven command...
editor.addCommand( 'yourCommand', new CKEDITOR.dialogCommand( 'link', {
allowedContent: 'a[!href]', // Allow <a> in the editor with mandatory href attr.
requiredContent: 'a[href]' // This command requires <a> with href to be enabled.
} ) );

或者在编辑器的配置中使用 config.extraAllowedContent = 'a[!href]' .虽然在开发插件时不推荐这样做(对吧?),它应该带有自定义命令。

关于ckeditor - 在 CKEditor 中插入一个链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18280063/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com