Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Cách Mở Liên Kết Trong Tab Mới Bằng HTML

Mặc định link mở trong cùng tab. Để giữ người dùng trên trang, mở link ngoài trong tab mới bằng target="_blank".

Cú Pháp

<a href="https://example.com" target="_blank" rel="noopener noreferrer">Mở Tab Mới</a>

Giải thích:

  • target="_blank": mở trong tab/cửa sổ mới (tùy cài đặt trình duyệt).
  • rel="noopener": ngăn trang mới truy cập window.opener (bảo mật).
  • rel="noreferrer": không gửi Referer header (riêng tư, SEO).

Ví dụ hoàn chỉnh:

<html>
<head><title>Link Tab Mới</title></head>
<body>
  <a href="https://placekitten.com/1000/1000" target="_blank" rel="noopener noreferrer">Xem Mèo Con!</a>
</body>
</html>

Luôn thêm rel="noopener noreferrer" khi dùng target="_blank" để an toàn.