Vinícius Félix
Vinícius Félix

Reputation: 8811

How can I make an icon open a hyperlink in new tab by default?

Currently I have a Quarto Blog with some icons in the navigation menu, each of them have a hyperlink to another site, but they do not open in another tab, instead they open in the same tab as the blog.

The icons are configured inside the file _quarto.yml, like this:

  navbar:
    left:
      - icon: stack-overflow
        href: https://stackoverflow.com/users/9696037/vin%c3%adcius-f%c3%a9lix  

I read the documentation , and did some research, I found methods, such as using target = "_blank", but I do not know how to configure it inside quarto.

Upvotes: 2

Views: 953

Answers (2)

Matt
Matt

Reputation: 61

Use the target: option within - icon:

navbar:
    left:
      - icon: stack-overflow
        href: https://stackoverflow.com/users/9696037/vin%c3%adciusf%c3%a9lix
        target: _blank

Quarto documentation on navigation items here.

Upvotes: 1

TomBen
TomBen

Reputation: 412

You can use Lua filter to open external links in a new tab:

function Link(link)
  if link.target:match '^https?%:' then
    link.attributes.target = '_blank'
    return link
  end
end

The code was shared by @tarleb on Mastodon.

The document on how to use Lua filters in Quarto.

Upvotes: 4

Related Questions