Developer forum

Forum » CMS - Standard features » Set target on links in Quill

Set target on links in Quill

Kasper Legarth
Reply

Hello.

Im struggeling to make links made in quill open in a new tab.
From other forum posts, i understand that when a link is made in the RTE, it is not effected by the "Open external links in a new tab" website setting.

I don't see an option to set target on a link in the quill? What is the best practise here?


Replies

 
Suzi Louring
Suzi Louring
Reply

+1

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Maybe.

I think you should consider if external links should open in new windows - users knows how to handle that by them selves and if they dont, opening up a new window will probably confuse them.

That said, I am more fan of opening external links in new tabs/windows as a site wide setting instead of needing to take that into consideration every time a link is inserted.

That can be achieved with a simple script on the page:

document.addEventListener("DOMContentLoaded", function () {
    document.querySelectorAll("a").forEach(link => {
        const href = link.getAttribute("href");
        if (href && href.match(/^https?:\/\//i)) {
            link.setAttribute("target", "_blank");
        }
    });
});

 

Other considerations with my chat with a smart tool (AI):
Forcing external links to open in a new window or tab is a common UX pattern, but it comes with both benefits and drawbacks. Whether or not to use it depends on the context of your website and its audience. Here's a breakdown of the UX considerations:


👍 Pros of Opening External Links in a New Tab

1. Prevents Losing the User’s Place

  • If the user is deep into your content and clicks an external link, they won’t lose their progress.
  • Especially useful for long articles, tutorials, or forms where users may need to reference an external resource but return to your page.

2. Keeps Users Engaged with Your Site

  • By keeping your site open in the background, it increases the chances that users will return instead of bouncing away permanently.
  • Helpful for blogs, e-commerce, or knowledge bases where retention matters.

3. Standard UX for Certain Types of Sites

  • Many news sites, blogs, and SaaS documentation pages open external links in a new tab to provide additional references without disrupting the reading experience.

4. Reduces Accidental Navigation Away

  • If users expect an external link to open in a new tab but it doesn’t, they might get frustrated when they leave your site unintentionally.

👎 Cons of Opening External Links in a New Tab

1. Takes Control Away from Users

  • Users expect to decide how a link opens (e.g., right-click → "Open in new tab").
  • Some users prefer to navigate back rather than having multiple tabs open.

2. Can Be Confusing for Less Tech-Savvy Users

  • Some users might not notice a new tab opened, especially on mobile where tab management is clunky.
  • They may think they "lost" your website if they don't realize it’s still open in another tab.

3. Inconsistent Behavior Across the Web

  • Some websites open external links in the same tab, others force a new one—this inconsistency can be jarring.
  • If a user expects a link to open in the same tab but it doesn’t, it can break their browsing flow.

4. Accessibility Concerns

  • Screen readers may not announce that a new tab was opened, leading to confusion for visually impaired users.
  • It’s best to provide a visual indicator (e.g., an external link icon) or an announcement ("opens in a new tab").

🛠 Best Practices If You Choose to Open External Links in New Tabs

If you decide that opening external links in a new tab is the best experience for your site, here’s how to make it more user-friendly:

Use an External Link Icon

  • Example: Add a 🔗 or an arrow icon () next to external links to visually indicate they behave differently.
  • Example:
    a[target="_blank"]::after {
        content: " ↗";
        font-size: 0.8em;
    }
    

Notify Users with Accessible Text

  • Use aria-label or title attributes:
    <a href="https://example.com" target="_blank" rel="noopener noreferrer" aria-label="Opens in a new tab">
        External Resource
    </a>
    
  • This ensures screen readers properly announce the new tab behavior.

Use rel="noopener noreferrer" for Security

  • Prevents security vulnerabilities when opening links in a new tab.

Be Consistent

  • If you do this for some links, do it for all external links to avoid confusion.

Let Users Decide When Possible

  • Consider not forcing links into a new tab unless it’s truly necessary (like preventing data loss on a form submission page).

🚀 Final Verdict: Should You Do It?

  • YES if your site is content-heavy (blog, documentation, news) and you want users to stay engaged with your page.
  • MAYBE if your users frequently navigate between your content and external references (like research or e-learning).
  • NO if it’s a standard website or users should be in control (e.g., an e-commerce site where users compare prices).

The best UX decision is the one that aligns with your users’ expectations and provides clear affordances so they know what to expect. 🚀

 
Kasper Legarth
Reply

Hi @Nicolai

I'm aware of the pros and cons. In my opinion, (and a lot of our customers) a CMS should give the editor the ability, one way or another. I agree that the best solution would be a website-wide option, but if i understand your reply here: https://doc.dynamicweb.com/forum/swift/swift/open-external-links-in-new-tab correctly, the option (open external links in a new window) for that is not site-wide? 

I don't see a way to add the target attribute in the link selector in RTE.

I don't see it as a viable solution to add some JavaScript to manipulate links to do something different than what was set up by the cms. I'm aware that you have updated the link picker in the RTE to match the link picker for buttons etc, but it is still not affected by the "open in new tab" site setting. Are there any plans to change that, or another way to give the ability to change the target on RTE links?

- Kasper

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

The feature from the above thread is a Swift 1 feature where the logic was targetting specific instances of links. My proposed JS will target all external links, no matter what. Having external links in the navigation which was the topic in the above thread would also be handled by the JS.

I have added a task to add a checkbox when inserting external links in the RTE to open in new window/tab. Devops#23026

This will not change all other external links though.

I would still recommend to not do anything but style external links - alternatively use the JS for consistency.

 

 
Rene Poulsen
Rene Poulsen
Reply

+1

To me this is just basic and needs to be an option in the RTE. We're not going to create js that manipulates the links. This simply just shouldn't be necessary to create links opening in a new window.

 
Rene Poulsen
Rene Poulsen
Reply

Can I give 2 +1s? ;-) We've got several customers asking for this. I know there's a lot of things to be done when swittching RTE, like you did from DW9 to DW10, but I just need to mention it again. It just seems so basic that I'm really surprised that you didn't add this feature to the new RTE. So I really hope this basic feature will be reintroduced very soon.

 
Rene Poulsen
Rene Poulsen
Reply

An argument for why it should be possible: https://www.civicengagecentral.civicplus.help/hc/en-us/articles/115004785034-When-to-Set-Links-to-Open-in-the-Same-or-a-New-Window#:~:text=window%20or%20tab.-,Best%20Practice,not%20use%20the%20back%20button.

"Open Links to Documents In a New Window: All links to documents should open in a new window.

  • Reasoning: When people finish using/reading PDF files and similar documents, research has shown that they click the window's close box and do not use the back button. This action closes their entire browser window. Instead, you should point them back to the webpage from where they started."
 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

As mentioned we did put it into the backlog.

That article, by the way, says that linking to documents (Like pdfs) should open in new windows, anything else should not...

 
Rene Poulsen
Rene Poulsen
Reply

@Nicolai. Great that it's in the backlog.

Yeah, I saw that as well. My problem (our customers problem) is especially with PDFs / documents.

 

You must be logged in to post in the forum