Lock: mode property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc mode của giao diện Lock trả về chế độ truy cập được truyền vào LockManager.request() khi khóa được yêu cầu. Chế độ có thể là "exclusive" (mặc định) hoặc "shared".

Giá trị

Một trong hai giá trị "exclusive" hoặc "shared".

Ví dụ

Các ví dụ sau đây minh họa cách thuộc tính mode được truyền vào lời gọi LockManager.request(). LockManager là đối tượng được trả về bởi navigator.locks.

js
// Should show "exclusive" (the default)
navigator.locks.request("my_resource", showLockProperties);

// Should show "exclusive"
navigator.locks.request(
  "my_resource",
  { mode: "exclusive" },
  showLockProperties,
);

// Should show "shared"
navigator.locks.request("my_resource", { mode: "shared" }, showLockProperties);

function showLockProperties(lock) {
  console.log(`The lock name is: ${lock.name}`);
  console.log(`The lock mode is: ${lock.mode}`);
}

Thông số kỹ thuật

Specification
Web Locks API
# dom-lock-mode

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