Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

แอตทริบิวท์ target ของ <a> ใน HTML


แอตทริบิวท์ target ของ <a> ใน HTML

แอตทริบิวท์ target ขององค์ประกอบ <a> ใช้สำหรับกำหนดว่าจะเปิดเอกสารที่ลิงก์ไปที่ไหน คุณสามารถตั้งค่าให้เปิดในหน้าต่างใหม่, เฟรมเดียวกัน, เฟรมพาเรนต์ ฯลฯ

รูปแบบการใช้งานมีดังนี้:

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

โดย _blank ใช้เปิดเอกสารที่ลิงก์ในหน้าต่างหรือแท็บใหม่ _self เปิดในเฟรมเดียวกับที่คลิก _parent เปิดในเฟรมพาเรนต์ _top เปิดในทั้งหน้าต่าง frame เปิดในเฟรมที่มีชื่อ

ตัวอย่าง

<!DOCTYPE html>
<html>
<body>
  <h2>การเรียนรู้สนุก</h2>
  <p><strong>หมายเหตุ -</strong> ลิงก์จะเปิดในหน้าต่างใหม่</p>
  <p><a href="https://www.tutorialspoint.com/tutorialslibrary.htm" target="_blank">Tutorials Library</a><br>
  <a href="https://www.tutorialspoint.com/programming_examples/" target="_blank">Codes</a><br>
  <a href="https://www.tutorialspoint.com/computer_glossary.htm" target="_blank">Computer Glossary</a> <br>
</body>
</html>

ผลลัพธ์จะเป็นดังนี้ ลิงก์ด้านล่างจะเปิดในหน้าต่างใหม่:

แอตทริบิวท์ target ของ <a> ใน HTML

ในตัวอย่างข้างต้น เราได้ตั้งค่า target ในแอตทริบิวท์ target:

<a href="https://www.tutorialspoint.com/tutorialslibrary.htm" target="_blank"> Tutorials Library </a>

แอตทริบิวท์ที่ตั้งค่าไว้ข้างต้นมีค่า _blank ซึ่งเปิดลิงก์ใน href ในหน้าต่างใหม่:

target="_blank"