PushSubscription: endpoint property
注意:此功能在 Web Workers 中可用。
PushSubscription 介面的 **endpoint** 只讀屬性返回一個字串,其中包含與推送訂閱關聯的端點。
此端點是一個指向推送伺服器的自定義 URL,可用於向訂閱了推送服務的特定 service worker 例項傳送推送訊息。因此,最好對端點保密,以防止他人劫持和濫用推送功能。
值
字串。
示例
js
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.subscribe({ userVisibleOnly: true }).then((subscription) => {
console.log(subscription.endpoint);
// At this point you would most likely send the subscription
// endpoint to your server, save it, then use it to send a
// push message at a later date
});
});
規範
| 規範 |
|---|
| 推送 API # dom-pushsubscription-endpoint |
瀏覽器相容性
載入中…