Have it set correctly:
But external links are opening in the same tab.
Is it a bug?
Are you overriding it with your personal preferences?
For reference, that’s under Preferences > Interface > Open all external links in a new tab
.
If you change your preference here on Meta (and reload the site), does it work as you expect on this forum?
Yes, I just set it on here in my preferences and it opened an external link in a new tab.
Then this doesn’t seem to be a bug in Discourse.
Is there something special about your forum? Have you tried safe mode? Is there a plugin that could cause this?
Nothing special. Self hosted on Hostinger Ubuntu. I disabled all plugins also. I will try safemode.
For anyone else that has this issue, here is the fix. Just create a theme component and add this code to the js section:
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("1.8.0", (api) => {
api.decorateCookedElement(
(element) => {
element.querySelectorAll("a[href^='http']").forEach((link) => {
if (link.hostname !== window.location.hostname) {
link.target = "_blank";
link.rel = "noopener noreferrer";
}
});
},
{ id: "external-links-new-tab" }
);
});