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