0

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?

enter image description here

1
  • You can look into a CKEditor plugin to do it, or make a simple one yourself.
    – jrothafer
    Aug 22 '19 at 19:56
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.