แท็ก <base> ใน HTML
แท็ก <base> ใน HTML ใช้สำหรับตั้งค่า URL พื้นฐาน (base URL) สำหรับเอกสาร HTML ตัวอย่างเช่น base URL เป็น https://example.com/tutorials สำหรับ relative URLs ทั้งหมด เช่น /html, /java, /jquery ซึ่งจะกลายเป็น:
https://example.com/tutorials/html https://example.com/tutorials/java https://example.com/tutorials/jquery
หมายเหตุ: แท็ก <base> ไม่มีแท็กปิด นั่นคือไม่ต้องปิดด้วย </base>
แอตทริบิวท์ต่อไปนี้:
- href: ตั้งค่า base URL สำหรับ relative URLs ทั้งหมดในหน้า
- target: เป้าหมายเริ่มต้นสำหรับไฮเปอร์ลิงก์และฟอร์มทั้งหมด ค่าสามารถเป็น _blank, _parent, _self, _top และ framename
ตัวอย่าง
<!DOCTYPE html> <html> <head> <base href="https://www.example.com/tutorials/"> </head> <body> <h2>รายการบทเรียน</h2> <p><a href="java.html">Java Tutorial</a></p><p>(นี่จะทำงานเป็น https://www.example.com/tutorials/java.html)</p> <p><a href="jquery.html">jQuery Tutorial</a></p><p>(นี่จะทำงานเป็น https://www.example.com/tutorials/jquery.html)</p> <p><a href="blockchain.html">Blockchain Tutorial</a></p><p>(นี่จะทำงานเป็น https://www.example.com/tutorials/blockchain.html)</p> <p><a href="python.html">Python Tutorial</a></p><p>(นี่จะทำงานเป็น https://www.example.com/tutorials/python.html)</p> </body> </html>
ผลลัพธ์
