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?
1 Answer
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');
}
});
}