Skip to content
Public Ticket #24928

Open in a new Tab all links

Conversation thread

LillaGreen replied

Customer Reply

Thank you!

LillaGreen started the conversation

Conversation Start

Hi, I want that all links open in a new tab, instead of editing those every single time.

Can I use the script:

function autoblank() {
    var links = document.links;
    for (let i = 0, linksLength = links.length ; i < linksLength ; i++) {
        if (links[i].hostname !== window.location.hostname) {
            links[i].target = '_blank';
            links[i].rel = 'noopener noreferrer';  // This is for security purposes
        }
    }
}
autoblank();


is it correct and Should I add it to my footer.php ? Is there a better option than that? Thank you!

Want to join this conversation or access attachments? Sign in first.