Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RMarkdown html _site.yml navbar href链接,在新选项卡中打开,目标="_“空白”;_Html_R_R Markdown - Fatal编程技术网

RMarkdown html _site.yml navbar href链接,在新选项卡中打开,目标="_“空白”;

RMarkdown html _site.yml navbar href链接,在新选项卡中打开,目标="_“空白”;,html,r,r-markdown,Html,R,R Markdown,与R Markdown HTML_site.yml页面斗争。在我的导航栏中,我的href指向不同的网站链接,我无法确定在哪里包含这些链接 target="_blank" 语句,以便在新选项卡中打开链接。Href链接不遵循RMarkdowns\u site.yml文件中的正常html格式 -文本:“推特” 图标:fatwitter href:https://twitter.com -文本:“GITHUB” 图标:fagithub href:https://github.com -正文:“松弛”

与R Markdown HTML_site.yml页面斗争。在我的导航栏中,我的href指向不同的网站链接,我无法确定在哪里包含这些链接

target="_blank"
语句,以便在新选项卡中打开链接。Href链接不遵循RMarkdowns\u site.yml文件中的正常html格式

-文本:“推特”
图标:fatwitter
href:https://twitter.com
-文本:“GITHUB”
图标:fagithub
href:https://github.com
-正文:“松弛”
图标:fa slack
href:https://slack.com

您可以为每个页面创建重定向页面,如下所示:

    - text: "TWITTER"
  icon: fa-twitter
  href: twitter_redirect.html
然后对于twitter_redirect.html(etc),使用window.open,后跟window.history.back

<!DOCTYPE html>

<html>
<head>
</head>
<body onload="myFunction()">

  <script>
    function myFunction() {
    window.open('https://twitter.com/', '_blank');
    window.history.back();
    }
  </script>
</body>

函数myFunction(){
打开窗户https://twitter.com/","空白",;
window.history.back();
}

基本上,最好的做法是创建一个js代码,自动向任何外部链接添加
target=“\u blank”
。并考虑到
rmarkdown
生成的内部链接是相对的。我们可以轻松创建一个正则表达式来测试是否存在外部链接,然后如果找到append
target=“\u blank”

首先创建:links.js
(函数(){
for(document.getElementsByTagName('a')的常量链接){
如果(/^(https?:)?\/\/.test(link.getAttribute('href'))link.target='u blank';
}
})();
添加脚本标记以包括_footer.html

在_site.yml中包含_页脚
输出:
html_文件:
包括:
正文后:包含页脚.html

参考@Abdessabour Mtk的JScode

---  
title: "BookMark"  
output: html_document  
---  

```{r setup, include=FALSE}  
knitr::opts_chunk$set(echo = TRUE)  
library(knitr)  
```  

[google](https://www.google.com)  
...

```{js, echo=FALSE}  
(function() {  
  for (const link of document.getElementsByTagName('a')) {  
    if (/^(https?:)?\/\//.test(link.getAttribute('href'))) link.target = '_blank';  
  }  
})();  
```  

看看这里:不完全是我要找的。我可以在HTML文件中使用“”链接。我特别想在我的_site.yml导航文件中找到一种方法,在导航栏的新选项卡中打开链接。@KevinMagnan您现在找到解决方案了吗?@jwarzinterested@jwarzRockScience没有,从来没有找到一个解决方案来解决那些只在同一个页面上打开的链接。最后,我把这个应用到我的网站上,它就像一个魅力(除了讨厌的弹出窗口拦截器)。谢谢!这很有效,但需要创建和维护一个中间页面。请参阅Abdessabour的解决方案,它非常优雅。它看起来像一个优雅的解决方案,但我无法让它工作。你将links.js保存在哪里?是否足够将其保存到页脚?将
link.js
保存在与页脚相同的文件夹中。是的,如果你将c中的
js
文件的内容footer@RockScience如果你有一个js文件夹,那么把它放进去,然后更改
script
tag的
src
attrib谢谢!为了参考,我不得不将
links.js
移动到footer.html的最终位置(即:子文件夹内/_站点)。它现在就像一个符咒一样工作