Opening links in a new tab

Anirudh Yadav 2019-12-17 1 minute read

For inline links, use the following syntax:

[link text](https://example.org){target="_blank"}

But obviously, it would be fairly annoying to append {target="_blank"} every time you want to add an inline link. Unsurprsingly, Yihui has a detailed post about this issue where he provides a Javascript function to automatically open external links in new tabs. Note that you have to make sure the baseURL in the config.toml file is set to "/" to make sure internal links don’t open in new tabs.

To implement Yihui’s external-link.js function, I saved it in the static folder, and then call the script in the header.html file, in the partials folder.