gpt4 book ai didi

javascript - CKEditor 如何在小部件中允许 href ="javascript:void(0)"

转载 作者:行者123 更新时间:2023-11-30 00:09:06 25 4
gpt4 key购买 nike

关于如何让 CKEditor 将 href="javascript:void(0)" 保留在我放置在小部件模板中的链接中,我找不到一个干净的解决方案。当我保存它时,通过调用 CKEDITOR.instances.*.getData(),它返回 href="javascript void(0)"

我尝试在 config.js 中设置 config.allowedContent = true; & config.linkJavaScriptLinksAllowed = true;,但它们似乎都没有做任何事情。 .

我已阅读 this page它表明这应该被修复,但这不起作用。有什么想法吗?

下面是有趣的简化 plugin.js 部分。这允许在链接中使用 href 属性,但它仍然会删除 :

template: 
'<div class="container">' +
'<a href="javascript:void(0)">' +
'<span class="label">Label</span>' +
'</a>' +
'</div>',

allowedContent:
'a[href]; div(*); span(*);',

editables: {
Label: {
selector: '.label',
allowedContent: ''
}
}

CKEditor 版本:4.5.9浏览器:Chrome

最佳答案

bug fix您在变更日志中发现仅针对链接对话框实现,因此它仅在通过插件对话框插入链接时有效。

据我了解,您的情况有所不同,因为您使用的是 href="javascript:void(0) 的链接。作为小部件模板的一部分。不确定您的模板结构是什么以及您如何创建小部件,但是在创建它时您可以使用 editables 属性来定义小部件的这个可编辑部分中允许的元素:

editables: {
content: {
selector: '.widget-content',
allowedContent: 'p a[href]'
}
}

所以使用 allowedContent 您为小部件的这一部分定义允许的内容 - 在本例中为 p标签和一个 a标记为 href属性。有了这样的配置<a href="javascript:void(0)">Link</a>应该正确插入。

您可以阅读有关允许的内容规则的更多信息 in the documentation .

关于javascript - CKEditor 如何在小部件中允许 href ="javascript:void(0)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37259821/

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