Clients: get() 方法

Baseline 已廣泛支援

此功能已成熟,可跨多種裝置和瀏覽器版本工作。它自 ⁨2018 年 4 月⁩ 起已在所有瀏覽器中可用。

注意:此功能僅在 Service Workers 中可用。

Clients 介面的 get() 方法根據給定的 id 獲取一個 service worker 客戶端,並將其以 Promise 的形式返回。

語法

js
get(id)

引數

id

一個字串,表示要獲取的客戶端的 id。

返回值

一個 Promise,它解析為 Client 物件或 undefined

示例

js
self.clients.get(id).then((client) => {
  self.clients.openWindow(client.url);
});

規範

規範
Service Workers
# clients-get

瀏覽器相容性