当我在代码中添加 target= "_blank" 时,它仍然在单击它的保存窗口中打开



正如我所说的,当我在代码中添加 target="_blank"时,它仍然会在单击的保存窗口中打开。我尝试将target="_blank放在前面和后面代码,但我似乎没有使它起作用。你能帮助我吗?这是我正在使用的HTML:`

<!doctype html>
<html>
    <head>
        <title>TacoMannen</title>
        <link rel="stylesheet" type="text/css" href="TacoSite CSS.css">
    </head>
    <body>
        <br>
        <button target="_blank" class="button Kalender disabled" onclick="location.href='/kalender'" >Kalender</button>
        <button target="_blank" class="button blogg" onclick="location.href='/blogg'" >Blogg</button>
        <button target="_blank" class="button kontakt" onclick="location.href='/kontakt-meg'" >Kontakt Meg</button>
        <button target="_blank" onclick="location.href='https://www.youtube.com/channel/UC1T-CxkwZ8fLDzlmIOM2Rxw?view_as=subscriber'" type="button" >Min Kanal</button>
        <br>
    </body>
</html>

这是我正在使用的CSS:

.button {
    background-color: white;
    color: black;
    border: 2px solid #4CAF50;
}
.button:hover {
    background-color: #4CAF50;
    color: white;
}

和摘要(如果需要):

.button {
  background-color: white;
  color: black;
  border: 2px solid #4CAF50;
}
.button:hover {
  background-color: #4CAF50;
  color: white;
}
<!doctype html>
<html>
<head>
  <title>TacoMannen</title>
  <link rel="stylesheet" type="text/css" href="TacoSite CSS.css">
</head>
<body>
  <br>
  <button target="_blank" class="button Kalender disabled" onclick="location.href='/kalender'">Kalender</button>
  <button target="_blank" class="button blogg" onclick="location.href='/blogg'">Blogg</button>
  <button target="_blank" class="button kontakt" onclick="location.href='/kontakt-meg'">Kontakt Meg</button>
  <button target="_blank" onclick="location.href='https://www.youtube.com/channel/UC1T-CxkwZ8fLDzlmIOM2Rxw?view_as=subscriber'" type="button">Min Kanal</button>
  <br>
</body>
</html>

,如果人们可以指出我不知道的其他错误,那太好了: - )

您必须使用<a>标签而不是<button>标签,因为它们没有target属性或href。您正在指示使用JavaScript而不是普通href打开的页面。您有两个选择:

  1. 将其更改为<a href="">

    <a target="_blank" class="button Kalender disabled" href="/kalender">Kalender</a>
    
  2. 使用window.open用于<button>

    <button class="button Kalender disabled" onclick="window.open('/kalender');" >Kalender</button>