BackgroundFetchUpdateUIEvent: updateUI() 方法
注意:此功能僅在 Service Workers 中可用。
BackgroundFetchUpdateUIEvent 介面的 updateUI() 方法更新使用者介面中的標題和圖示,以顯示後臺獲取的狀態。
此方法只能執行一次,用於通知使用者獲取失敗或成功。
語法
js
updateUI()
updateUI(options)
引數
返回值
異常
InvalidStateErrorDOMException-
如果出現以下任一情況,則丟擲。
isTrusted屬性為false。BackgroundFetchUpdateUIEventUI 更新標誌已設定,表明updateUI()方法已被呼叫。BackgroundFetchUpdateUIEvent未啟用。
示例
以下示例演示了在成功獲取時使用標題和影像圖示更新 UI。
js
addEventListener("backgroundfetchsuccess", (event) => {
event.updateUI({
title: "Episode 5 ready to listen!",
icon: {
src: "path/to/success.ico",
sizes: "16x16 32x32 64x64",
},
});
});
規範
| 規範 |
|---|
| Background Fetch # background-fetch-update-ui-event-update-ui |
瀏覽器相容性
載入中…