使用html在同一选项卡中打开链接

pep*_*ito 6 html

我想在单击一个单词时用html在同一个选项卡中打开一个链接.尽管如此,即使我尝试使用target="_self"并且不使用任何目标,它只能使用target="_blank",但是,正如您所知,这将打开另一个选项卡中的链接.

码:

    <!DOCTYPE html>
<html>
<head>
<style type="text/css">
body
{
  min-width:360px;
}
a{
   color:#009900;
   text-decoration:none;
}
a:hover
{
  text-decoration:underline;
}
p
{
  font:0.8em sans-serif;
}
h1
{
  font:1.5em sans-serif;
  color:#fff;
  background:#006600;
  padding:5px
}
</style>
</head>

<body>
  <h1>play</h1>
 <p><a href="https://www.youtube.com" target="_blank">YT player</a></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

小智 6

<a target="_self" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

使用 _self

<a target="_self" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)


use*_*363 5

在同一选项卡中打开链接

<a target="_self" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

每次单击链接时都会添加一个新选项卡,并在其中打开链接

<a target="_blank" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

仅创建一次新选项卡,并在创建的同一新选项卡中打开链接(不是每次都创建新选项卡)

<a target="_new" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

仅创建一次新选项卡并在同一个新选项卡中打开链接(不是每次都创建新选项卡,而是在由其给定 ID 创建的特定选项卡中打开链接。您可以使用不同的 ID 创建多个选项卡。)

<a target="myYTPlayerTab" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

如果链接的目标属性与同一页面上的 iframe 名称匹配,则链接将在该 iframe 中打开。

<a target="myYTPlayerIframe" href="https://www.youtube.com" >YT player</a>
<iframe src="demo_iframe.htm" name="myYTPlayerIframe" height="300px" width="100%" title="Iframe Example"></iframe>
Run Code Online (Sandbox Code Playgroud)

如果用户位于子框架内,它将打开父 iframe 中的链接

<a target="_parent" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)

如果用户位于框架中,则会打开顶部 iframe 中的链接

<a target="_top" href="https://www.youtube.com" >YT player</a>
Run Code Online (Sandbox Code Playgroud)