Lock:mode 属性

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.

安全上下文: 此项功能仅在一些支持的浏览器安全上下文(HTTPS)中可用。

备注: 此特性在 Web Worker 中可用。

Lock 接口的 mode 只读属性返回请求锁时传递给 LockManager.request() 的访问模式。该模式可以是 "exclusive"(默认值)或 "shared"

"exclusive""shared" 之一。

示例

以下示例显示如何在对 LockManager.request() 的调用中传递 mode 属性。其中 LockManagernavigator.locks 返回的对象。

js
// 应显示 "exclusive"(默认值)
navigator.locks.request("my_resource", show_lock_properties);

// 应显示 "exclusive"
navigator.locks.request(
  "my_resource",
  { mode: "exclusive" },
  show_lock_properties,
);

// 应显示 "shared"
navigator.locks.request(
  "my_resource",
  { mode: "shared" },
  show_lock_properties,
);

function show_lock_properties(lock) {
  console.log(`锁的名称是:${lock.name}`);
  console.log(`锁的模式是:${lock.mode}`);
}

规范

Specification
Web Locks API
# dom-lock-mode

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
mode

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support