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

วิธีลิงก์หน้าเว็บด้วย Absolute URL ใน HTML

Absolute URL ใช้สำหรับลิงก์ไปยังเว็บไซต์ภายนอก (External Links) ต้องระบุโปรโตคอลและ domain เต็ม

รูปแบบ Absolute URL

https://www.example.com/page.html
https://subdomain.example.com/path
mailto:user@example.com
tel:+66812345678

Attribute ของ <a> tag

Attributeคำอธิบาย
hrefURL ปลายทางเต็ม (จำเป็น)
relความสัมพันธ์: nofollow, external, author, bookmark
targetเป้าหมาย: _blank (แนะนำสำหรับ external), _self
titleTooltip เมื่อ hover

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
  <title>HTML Absolute links</title>
</head>
<body>
  <h1>Qries</h1>
  <p>
    With <a href="https://www.qries.com/questions.php" target="_blank" rel="noopener noreferrer">Qries</a>,
    get information about different topics such as games, government, education, geology, sports, etc.
  </p>
</body>
</html>

แนวทางปฏิบัติที่ดีสำหรับ External Links

<a 
  href="https://example.com" 
  target="_blank" 
  rel="noopener noreferrer external nofollow"
  title="Visit Example.com (opens in new tab)"
>
  Example.com
</a>

ข้อควรทราบ

  • Absolute URL จำเป็นสำหรับ external links
  • Relative URL ไม่ทำงานสำหรับ cross-domain
  • Protocol-relative URL (//example.com) deprecated แล้ว ควรระบุ https:// เสมอ