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.tw/java/index.htm">Java Tutorial</a></p> <p>(This will act as https://tutorialspoint.tw/java/index.htm)</p> <p><a href="https://tutorialspoint.tw/jquery/index.htm">jQuery Tutorial</a></p> <p>(This will act as https://tutorialspoint.tw/jquery/index.htm)</p> <p><a href="https://tutorialspoint.tw/blockchain/index.htm">Blockchain Tutorial</a></p> <p>(This will act as https://tutorialspoint.tw/blockchain/index.htm)</p> <p><a href="https://tutorialspoint.tw/python/index.htm">Python Tutorial</a></p> <p>(This will act as https://tutorialspoint.tw/python/index.htm)</p> </body> </html>
這將產生以下輸出。當你點選以下任何一個連結時,它將在新視窗中開啟,因為它被設定為 _blank −
上面,我們設定了基本 URL -
<base href="https://tutorialspoint.tw/tutorialslibrary.htm" target="_blank">
所有 URL 現在都將在新視窗中開啟,因為我們已將 <base> 元素的 target 屬性設定為 −
target="_blank"
廣告