Hướng dẫn anchor php

  • Trang chủ
  • Tham khảo
  • Tag html
  • html5

Nội dung chính

  • Định nghĩa và sử dụng
  • Cấu trúc
  • Ví dụ: Liên kết tới trang khác
  • Ví dụ: Liên kết mail
  • Ví dụ: Link từ vị trí này tới vị trí khác
  • Ví dụ: Link để mở file word (tương tự cho những định dạng khác)
  • Ví dụ: Liên kết mở ra cửa sổ khác
  • Trình duyệt hỗ trợ
  • Thuộc tính

Định nghĩa và sử dụng

Tag xác định một siêu liên kết (hyperlink).
Được dùng để:

Xem ví dụ.

Sự khác nhau giữa HTML4.01 và HTML5

HTML4.01HTML5
● Sử dụng như siêu liên kết (link) hay một neo (anchor) ● Luôn luôn là siêu liên kết (link).
● Nếu không có thuộc tính href thì nó chỉ là một trình giữ chỗ cho một liên kết.
● Trong HTML5 có một số thuộc tính mới, và một số thuộc tính không được hỗ trợ.

Cấu trúc

Đây là link

Ví dụ: Liên kết tới trang khác

Html viết:

Liên kết tới trang khác

Hiển thị trình duyệt:

Ví dụ: Liên kết mail

Html viết:

Hiển thị trình duyệt:

Khi click vào sẽ xuất hiện một hộp thư gửi mail.

Html viết:

Liên kết tới id content

Hiển thị trình duyệt:

Html viết:

Mở file ex.doc trong thư mục "doc"

Hiển thị trình duyệt:

Ví dụ: Liên kết mở ra cửa sổ khác

Html viết:

Liên kết mở ra cửa sổ khác

Hiển thị trình duyệt:

Trình duyệt hỗ trợ

Tag được hỗ trợ trong đa số các trình duyệt.

Thuộc tính

Cách sử dụng:

Thuộc tính tùy chọn

Thuộc tínhGiá trịVí dụMô tả
Thuộc tính mới (Mới)
media truy vấn media media="screen" Xác định mục tiêu URL cho media/device.
Giá trị mặc định là: all.
type Kiểu MIME type="image/gif" Xác định kiểu MIME cho mục tiêu URL.
Thuộc tính như HTML4.01
href URL href="index.html" Đường dẫn cụ thể đến một liên kết.
target _blank
_parent
_self
_top
framename
target"_blank" Xác định nơi để mở tài liệu.
Thuộc tính không hỗ trợ trong HTML5
charset Bộ mã ký tự charset="UTF-8" Không hỗ trợ trong HTML5.
coords Tọa độ coords="0,111,122" Không hỗ trợ trong HTML5.
name Tên name="products" Không hỗ trợ trong HTML5.
rev Text rev="ourWeb" Không hỗ trợ trong HTML5.
shape default
rect
circle
poly
shape"circle" Không hỗ trợ trong HTML5.
Thuộc tính không được hỗ trợ trong phần lớn các trình duyệt
hreflang Mã ngôn ngữ hreflang="vi" Xác định rõ ngôn ngữ của văn bản được liên kết.
Không hỗ trợ trong phần lớn trình duyệt
rel Text rel="ourWeb" Xác định mối quan hệ giữa các văn bản hiện tại và văn bản được liên kết.
Không hỗ trợ trong phần lớn trình duyệt

Thuộc tính Tổng quát và thuộc tính sự kiện

Tất cả thuộc tính tổng quát và thuộc tính sự kiện được xác định trên phần lớn các thành phần HTML5

I try to use the anchor tag with the include I have. On my Index.php I got a little "nav bar" with some anchor tags. I also included the file "text.php" in my code. This file is in the Folder "texte". The anchor tags should bring the user to the position in text.php but it only load 404 - page not found.

How I include the file:


I declare my "start-word" like this:

Informationen

And my anchor like this:

Informationen

I also tried Informationen because of the include but it came out the same result.

Any ideas?

asked Jul 31, 2019 at 10:58

qpAqpA

751 silver badge8 bronze badges

8

If

Informationen

is generated somewhere within your page and sent to the browser, then an anchor link should work correctly as

Informationen

One think I noticed from your example is that you should make sure you use " not for quote marks - these are not the same characters, and you must use the correct one.

Clicking on an anchor link should not result in a 404 error, if it's correctly defined. Even if the anchor ID doesn't actually exist in the page, it still wouldn't give a 404 - the worst that would occur would be that nothing would happen.

answered Jul 31, 2019 at 11:27

Hướng dẫn anchor php

ADysonADyson

53.2k13 gold badges48 silver badges61 bronze badges

Additionally to what @ADyson said:

Anchor links work on the browser side. The form #InfoAnker redirects to an anchor on the same page, while texte/text.php#InfoAnker redirects to another page. Again: on the browser side.

But I see, you are using includes, which work on server side. Normally, you don't have the same path and file structure on server and client (if your server include is located outside of wwwroot for example, but also for hiding confidential data and your program structure). This is most likely the reason why you see the 404. So if you want to access the piece of text that was included in your script, your redirect must not have a url.

But for this to work, you need to define the anchor itself, using

Informationen

, either in the include or in the file which includes text.php

answered Jul 31, 2019 at 11:38

Daniel AlderDaniel Alder

4,7302 gold badges46 silver badges51 bronze badges