【发布时间】:2019-09-20 00:02:28
【问题描述】:
我正在使用 Docusaurus,并希望在新标签页中打开外部链接。
我更愿意为此使用代码,而不是按照this answer 在我的 Markdown 文档中编写 html 代码的解决方案。
我试过this answer:
[link](url){:target="_blank"}
还有this answer:
[Google](https://google.com" target="_blank)
我认为this post 可能会做我想做的事,我尝试将代码添加到 _index.js,但 Docusaurus 停止构建。
(function() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
if (/^(https?:)?\/\//.test(links[i].getAttribute('href'))) {
links[i].target = '_blank';
}
}
})();
我将 JavaScript 代码上传到 GitHub 并添加到 siteConfig.js:
// Add custom scripts here that would be placed in <script> tags.
scripts: [
"https://buttons.github.io/buttons.js",
"https://msdcanderson.github.io/docusaurus-open-link-new-tab.github.io/open-link-new-tab.js"
],
脚本似乎已加载,但未按预期工作。
我希望在新的浏览器选项卡中打开一个用 Markdown 编写的链接:
[the rmarkdown website](https://rmarkdown.rstudio.com)
任何想法都会很棒 - 谢谢
【问题讨论】:
标签: javascript reactjs markdown docusaurus