最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there anyway to stop CKEditor 4 from filtering my anchor tag attributes? - Stack Overflow

programmeradmin1浏览0评论

CKEditor 4 attribute filtering is stripping any occurrence "href" from anchor tags put into the editor. I have a plugin which creates links that contain some "custom" attributes. A link looks something like this:

<a href="#" document-href="abc123">Some Link</a>

The CKEditor returns the link in this form when I call getData():

<a href="#" document->Some Link</a>

Is there a way to instruct CKEditor to stop filtering link attributes? Does anyone happen to know where in the source this regex is so I can fix it?

Thanks!

CKEditor 4 attribute filtering is stripping any occurrence "href" from anchor tags put into the editor. I have a plugin which creates links that contain some "custom" attributes. A link looks something like this:

<a href="#" document-href="abc123">Some Link</a>

The CKEditor returns the link in this form when I call getData():

<a href="#" document->Some Link</a>

Is there a way to instruct CKEditor to stop filtering link attributes? Does anyone happen to know where in the source this regex is so I can fix it?

Thanks!

Share Improve this question asked Apr 3, 2013 at 18:28 NickNick 19.7k52 gold badges190 silver badges313 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

I've just checked this link on CKEditor 4.1 - the output is:

<p><a href="#">Some Link</a></p>

Since 4.1 the document-href is stripped because it is now allowed in the editor. You have to add an Advanced Content Filter rule - e.g.:

config.extraAllowedContent = 'a[!href,document-href]';

And then it would work in 4.1. Before 4.1 it should work by default, without setting anything.

However there's a bug in CKEditor's HTML parser. It does not parse correctly sth-href attributes on links so a result is a sth- attribute.

For now I advice you to change the name of this attribute to data-url or whatever else without href ending.

I created a ticket: https://dev.ckeditor./ticket/10298

try setting this in config file.

    config.allowedContent = true;

also if its getting filtered on insert then you can try this:

//var yourAnchor = '<a href="#" document-href="abc123">Some Link</a>';

editor.insertHtml(yourAnchor, 'unfiltered_html');
发布评论

评论列表(0)

  1. 暂无评论