将rel =“noopener”添加到ckeditor中的链接/锚点

时间:2016-10-19 22:24:07

标签: ckeditor

当用户在WYSIWYG视图中创建锚元素时,我想自动将rel="noopener"插入HTML。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以使用dataProcessor强制构建元素的方式:

dataProcessor.htmlFilter.addRules( {
    elements: {
        a: function( el ) {
            if ( !el.attributes.rel) {
                el.attributes['rel'] = 'noopener';
            }
        }
    }
});

这是一个有效的jsfiddle:
https://jsfiddle.net/25x37LgL/