Configure a custom sidebar link to open in a new tab

Is it possible to make custom section link go _blank in order to be opened in a new tab? There are many theme components providing this ability too

3 Likes

We did discuss at some point whether external links in the sidebar should open in a new tab, but decided to respect the user preference.

Can you share a case or two from your own site where you feel like it’d be better to override that user preference and force the link to open in a new tab?

2 Likes

Sure. Maybe our approach is just different. I truly believe if the link is external it is much polite to forward user’s browser to separate tab. That prevents them from interrupting the experience they have/had while being at Forum pages.

Our forum is highly active, not sure it’s okay for a user to be interrupted by leaving the website altogether by following the link. The link leads to our Telegram channel, if this is the case.

In the end, I do not propose making external links open _blank by default. I suggest you give Discourse admins an ability to control how any links open from this specific component/configuration feature

3 Likes

Temporary solution: If you right click on an item, you get the option to open it in a new tab.

Agreed, your progress would never get interrupted when links open in a new tab.

i tend to agree with this. like the above scenario with a telegram channel, clearly there are going to be cases where overriding the user preferences is ideal for admin created custom links. in theme components we target _blank often so i’m not sure why this option can’t be here as part of the custom side-bar config modal (unless it’s a case of real estate and there is no room there).

i actually have a admin customized side-bar links on my forum as well where i would be inclined to override the user setting for links.

1 Like

You believe that if the user has expressed the preference to have links opened in the same window it’s more polite not to do what they have expressly indicated?

People who use screen readers are the ones most inconvenienced by opening things in new tabs when they don’t expect it. That’s why it’s generally recommended not to hijack links into a new tab (even though it’s what you and I prefer).

You can change the user default preference to open in a new tab, and also apply that setting to all users. That will allow your site to be more polite without violating the user preferences.

3 Likes

this is a really good point.

4 Likes

As someone who actually uses a screen reader (and all the fun issues some theme components create for them) I can confirm, it’s generally a bad idea to force new tabs.

5 Likes

How can I disable the sidebar from opening a custom link to a sister website, in a new tab? Since the other website also has a link to return to Discourse. At present, it results in a number of unwanted tabs.

Would prefer just for that external link to open to _self.

Thanks

1 Like

Generally all links must open to _self. An user says when and which ones should open to new tab or window.

1 Like

In admin - settings, make sure the following is disabled:

Note that logged in users can override the admin settings in their user preferences under the interface tab:

2 Likes

I think the question was how to set this up for one specific link to the site, which has a link back to the forum. Changing the admin setting would change the behavior for all links, wouldn’t it?

2 Likes

hmmm, could be. Do they want to override the user settings? Those are the only settings I know of that affect links in separate tabs/windows.

1 Like

Yes, I don’t want to disable target _blank globally for external sites. Just want to disable it for this single menu item.

Thanks for explanation.

2 Likes

Custom Header Links lets you choose the target for the links it adds. Maybe this will help

3 Likes

Thanks. So use this for the sidebar?

1 Like

It’s a hint. It’s the best I’ve got. TBH I’m not sure about modifying the sidebar.

It seems that there are still no plugin outlets in the sidebar (!?), so it might take some clever javascript to find the thing you want to modify. Something like this, maybe.

3 Likes

This is intentional, ideally the sidebar should be extended using the API… this helps us maintain any custom links/sections added here.

At the moment it looks like the external link targets are all or nothing based on the user setting external_links_in_new_tab… so even with a custom section/link added via the API there’s not a method to change the target for a specific link. It would be possible to add this option… though historically we tend to lean towards respecting the user’s preference for how links are opened.

4 Likes

That explains it. I guess I missed that memo. But looking a bit more closely, I see addSidebarPanel and addSidebarSection in plugin-api.js but only the latter turns up a post, and it’s far from a how-to. But there’s this:

4 Likes