HTML <base> 目标属性


<base> 元素的 target 属性用于设置文档中超链接的默认目标。

语法

以下是语法 -

<base target="_blank|_self|_parent|_top| frame">

此处,_blank 用于在新窗口或选项卡中打开链接的文档,_self 打开链接的文档,位于与被点击的文档相同的框架内,_parent 在父框架中打开文档,_top 在窗口的整个正文中打开链接的文档,frame 在命名的框架中打开链接的文档。

示例

现在让我们看一个示例去实现 target元素的属性 -

<!DOCTYPE html>
<html>
   <head>
      <base href="https://www.example.com/tutorials/" target="_blank">
   </head>
   <body>
      <h2>Tutorials List</h2>
      <p><a href="https://tutorialspoint.com/java/index.htm">Java Tutorial</a></p>
      <p>(This will act as https://tutorialspoint.com/java/index.htm)</p>
      <p><a href="https://tutorialspoint.com/jquery/index.htm">jQuery Tutorial</a></p>
      <p>(This will act as https://tutorialspoint.com/jquery/index.htm)</p>
      <p><a href="https://tutorialspoint.com/blockchain/index.htm">Blockchain Tutorial</a></p>
      <p>(This will act as https://tutorialspoint.com/blockchain/index.htm)</p>
      <p><a href="https://tutorialspoint.com/python/index.htm">Python Tutorial</a></p>
      <p>(This will act as https://tutorialspoint.com/python/index.htm)</p>
   </body>
</html>

这将产生以下输出。当你点击以下任何一个链接时,它将在新窗口中打开,因为它被设置为 _blank −

上面,我们设置了基本 URL -

<base href="https://tutorialspoint.com/tutorialslibrary.htm" target="_blank">

所有 URL 现在都将在新窗口中打开,因为我们已将 <base> 元素的 target 属性设置为 −

target="_blank"

更新于:2024-2-29

372 浏览量

开启你的 职业生涯

完成课程以获得认证

开始
广告
© . All rights reserved.