Lately, all the external links on my forum have stopped opening into a new tab. I’ve double-checked the option “open external links in a new tab by default” and it is ticked:
Can you test this out here on Meta? Set your preferences here to open external links in a new tab and see if it works for you. It works quite well for me.
One of your best first step troubleshooting options would be to examine the DOM directly using the web dev console; and to inspect what are the exact attributes of your link, in particular, the “target” attribute.
Often, you cannot see these DOM attributes directly reading the source code (these attributes can exist in the DOM but not in source), and so you will need to query the DOM to get the attributes (to be 100% certain).
No. Reading the source code is not the same as checking the DOM.
DOM attributes can be different (and often are) than the source code; especially on web sites which use a lot of Javascript to manipulate the DOM (like Discourse).
That is why I mentioned specifically to query the DOM and not simply look at the source code
However, I agree with you @osioke, that the source code clearly shows the target attribute missing; but when we check the DOM, we will be “certain” what is the attribute; since the DOM can be in a different state than the source code (and often is in a different state).
Personally, I am a huge fan of “never assuming anything” so that is why I suggested that @riteshsaini “make sure” by checking the DOM and then “go from there”.
It is highly possible the DOM and the source code link target attributes are in the same state; but I always recommend folks troubleshooting problems not assume these kinds of details; hence my suggestion to query the DOM as a troubleshooting step.
<script type="text/discourse-plugin" version="0.8">
api.onPageChange((url, title) => {
// Automatically open external links in new tab or window
var pc = 1;
if ($("html").hasClass("mobile-device")) pc = 0;
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname) {
if (pc) links[i].target = '_blank'; else links[i].target = '_self';
}
}
});
</script>
… and illustrating perfectly in a solid Discourse API example how the DOM and the source code will be in a different state and you will not see the target attributes in the HTML source code set by the JS above
Have you checked the settings on your personal profile under preferences/interface? Because usually this situation is created when on your personal profile the opening of external links in new tabs is disabled.
It was unticked, so I ticked it. Now it opens the links in the new tab only when I’m logged in. If I check the site in the incognito tab, it still does not work.
For forums for the sharing and downloading using links out bitly or sites (less secure)
Would you consider using rel="noopener noreferrer" instead rel="nofollow"?
You can learn more about noopener noreferrer
I can consider adding noopener noreferrer but I will still need to add nofollow along with them. The thing is, I don’t want Google to follow or index those links because they are affiliate links. Only nofollow can help with that.