function insertnonopener(link) { let linkTypes = (link.getAttribute('rel') || '').split(' '); if (!linkTypes.includes('noopener')) { linkTypes.push('noopener'); } link.setAttribute('rel', linkTypes.join(' ').trim()); } function newtabmsg(link) { if (!link.querySelector('.screen-reader-only')) { link.insertAdjacentHTML('beforeend', '(opens in a new tab)'); } } document.querySelectorAll('a[target="_blank"]').forEach(link => { insertnonopener(link); newtabmsg(link); });