在ckeditor中添加rel="noopener"到links/anchors
Add rel="noopener" to links/anchors in ckeditor
当用户在 WYSIWYG 视图中创建锚元素时,我想自动将 rel="noopener"
插入到 HTML。
我怎样才能做到这一点?
您可以使用 dataProcessor
强制构建元素的方式:
dataProcessor.htmlFilter.addRules( {
elements: {
a: function( el ) {
if ( !el.attributes.rel) {
el.attributes['rel'] = 'noopener';
}
}
}
});
这是一个有效的 jsfiddle:
https://jsfiddle.net/25x37LgL/
当用户在 WYSIWYG 视图中创建锚元素时,我想自动将 rel="noopener"
插入到 HTML。
我怎样才能做到这一点?
您可以使用 dataProcessor
强制构建元素的方式:
dataProcessor.htmlFilter.addRules( {
elements: {
a: function( el ) {
if ( !el.attributes.rel) {
el.attributes['rel'] = 'noopener';
}
}
}
});
这是一个有效的 jsfiddle:
https://jsfiddle.net/25x37LgL/