PushSubscription: unsubscribe() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Phương thức unsubscribe() của giao diện PushSubscription trả về một Promise sẽ phân giải thành một giá trị boolean khi đăng ký hiện tại được hủy đăng ký thành công.

Cú pháp

js
unsubscribe()

Tham số

Không có.

Giá trị trả về

Một Promise sẽ phân giải thành một giá trị boolean khi đăng ký hiện tại được hủy đăng ký thành công.

Ví dụ

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    subscription
      .unsubscribe()
      .then((successful) => {
        // Bạn đã hủy đăng ký thành công
      })
      .catch((e) => {
        // Hủy đăng ký thất bại
      });
  });
});

Thông số kỹ thuật

Specification
Push API
# dom-pushsubscription-unsubscribe

Tương thích trình duyệt

Xem thêm