Lock

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

Lock interface of the the Web Locks API provides the name and mode of a previously requested lock, which is received in the callback to LockManager.request() .

特性

Lock.mode 只读
Returns the access mode passed to LockManager.request() when the lock was requested. The mode is either "exclusive" (默认) 或 "shared" .
Lock.name 只读
Returns the name passed to LockManager.request() when the lock was requested.

范例

The following examples show how the mode and name properties are passed in the call to LockManager.request() . LockManager is the object returned by navigator.locks .

navigator.locks.request("net_db_sync", show_lock_properties);
navigator.locks.request("another_lock", {mode: "shared"}, show_lock_properties);
function show_lock_properties(lock) {
  console.log(`The lock name is: ${lock.name}`);
  console.log(`The lock mode is: ${lock.mode}`);
}
					

规范

规范 状态 Comment
Web Locks API
The definition of 'Lock' in that specification.
草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Lock
Chrome 69 Edge ≤79 Firefox ? IE ? Opera 56 Safari ? WebView Android 69 Chrome Android 69 Firefox Android ? Opera Android 48 Safari iOS ? Samsung Internet Android 10.0
mode
Chrome 69 Edge ≤79 Firefox ? IE ? Opera 56 Safari ? WebView Android 69 Chrome Android 69 Firefox Android ? Opera Android 48 Safari iOS ? Samsung Internet Android 10.0
name
Chrome 69 Edge ≤79 Firefox ? IE ? Opera 56 Safari ? WebView Android 69 Chrome Android 69 Firefox Android ? Opera Android 48 Safari iOS ? Samsung Internet Android 10.0

图例

完整支持
完整支持
兼容性未知
兼容性未知
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。
  1. Lock
  2. 特性
    1. mode
    2. name