Is there an easy fix that will append rel='noopener'
to every link that’s set to open in a new window when using the hyperlink button in a text area field?
-
You can look into a CKEditor plugin to do it, or make a simple one yourself. – jrothafer Aug 22 '19 at 19:56
I opted for an easier approach and wrote a Javascript function instead which looks for any links with an attribute of target="_blank"
and adds rel="noopener"
.
function relnoopener() {
const a = document.querySelectorAll('a[target="_blank"]');
a.forEach(function(element) {
if (!element.hasAttribute('rel')) {
element.setAttribute('rel', 'noopener');
}
});
}