1

Getting external links set to target="_blank" is well-documented using client or server code:

It's 2015 and HTML and CSS has grown up since these questions. Is there a pure CSS3 or HTML5 solution to make external links leave the website, as in target=_blank but for all links?

Also tagging Jekyll since that's the platform I'm in, and a Jekyll flag, which would let Ruby do it server side, would be useful for me.

Community
  • 1
  • 1
djechlin
  • 59,258
  • 35
  • 162
  • 290
  • What are “these problems”? You should state the problem in the question itself. And preferably one problem per question. – Jukka K. Korpela Feb 27 '15 at 22:40
  • @JukkaK.Korpela I updated my question per your suggestion. Please let me know if this is OK. – djechlin Feb 27 '15 at 23:14
  • @JukkaK.Korpela I think there is only one problem. Was there a second problem I alluded to? The first problem I am trying to solve I am trying to do in a Jekyll website which may be relevant, and context is encouraged on SO questions, so I included the context. That may be the second problem you are referring to, but it's not really a separate question, since I only have one problem. – djechlin Feb 27 '15 at 23:16

3 Answers3

3

To suggest that a link be opened in a new browsing context (typically, a new tab or a new window), which is apparently what you mean by “leave the website”, you can use the target=_blank attribute. To set that the default for all links (and all form submissions), you can use the tag <base target=_blank>; this might be feasible if you want to handle most links that way and override the setting with target=_self as needed. Other than that, HTML has no tools for the purpose, and no concept of “external” vs. “internal” links. So you need to generate the attributes when generating the page, using whatever definition you have for “external”.

In CSS, there is in practice nothing that would help. Years ago, there was a proposed target-name property, in CSS3 Hyperlink Presentation Module WD in 2004. But it was never implemented, and work on the topic has been discontinued, as briefly described in CSS3 Hyperlink Presentation Module WG Note in 2014.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
0

Whether the link opens in the current tab or not doesn't involve presentation, so there definitely isn't a CSS option.

HTML doesn't contain any conditional logic that I know of, so it's also not possible there.

This is a perfect case for Javascript or a server side solution.

Chris Herbert
  • 6,145
  • 3
  • 19
  • 31
0

Try this:

<head>
<base target="_blank"></base>
</head>
Louis55
  • 408
  • 6
  • 17