PerformanceElementTiming: url property

Khả dụng hạn chế

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Thuộc tính chỉ đọc url của giao diện PerformanceElementTiming trả về URL ban đầu của yêu cầu tài nguyên khi phần tử là một hình ảnh.

Giá trị

Một chuỗi là URL ban đầu của yêu cầu tài nguyên cho hình ảnh hoặc 0 cho văn bản.

Ví dụ

Ghi lại url

Trong ví dụ này, một phần tử <img> đang được quan sát bằng cách thêm thuộc tính elementtiming. Một PerformanceObserver được đăng ký để lấy tất cả các mục hiệu suất loại "element" và cờ buffered được dùng để truy cập dữ liệu từ trước khi trình quan sát được tạo. Gọi entry.url trả về https://example.com/image.jpg.

html
<img
  src="https://example.com/image.jpg"
  alt="a nice image"
  elementtiming="big-image"
  id="myImage" />
js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.identifier === "big-image") {
      console.log(entry.url);
    }
  });
});
observer.observe({ type: "element", buffered: true });

Thông số kỹ thuật

Thông số kỹ thuật
Element Timing API
# dom-performanceelementtiming-url

Tương thích trình duyệt