SharedStorage: delete() method

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Phương thức delete() của giao diện SharedStorage xóa một cặp key-value hiện có khỏi bộ lưu trữ chia sẻ của nguồn gốc hiện tại.

Cú pháp

js
delete(key)

Tham số

key

Một chuỗi đại diện cho key của cặp key-value bạn muốn xóa.

Giá trị trả về

Một Promise thực hiện với undefined.

Ngoại lệ

  • Promise từ chối với TypeError nếu:
    • Cơ sở dữ liệu không được xóa thành công do bộ lưu trữ chia sẻ không khả dụng (ví dụ: bị tắt bởi cài đặt trình duyệt).
    • key vượt quá độ dài tối đa do trình duyệt xác định.
    • Trang gọi không có Shared Storage API được bao gồm trong quy trình đăng ký privacy sandbox thành công.
  • Trong trường hợp WorkletSharedStorage, Promise từ chối với TypeError nếu:

Note: Nếu cặp key-value không tồn tại trong bộ lưu trữ chia sẻ, không có lỗi nào được ném ra, thao tác vẫn thực hiện với undefined.

Note: Trong trường hợp WindowSharedStorage, nếu thao tác delete() không ghi thành công vào cơ sở dữ liệu vì lý do khác ngoài bộ lưu trữ chia sẻ không khả dụng, không có lỗi nào được ném ra, thao tác vẫn thực hiện với undefined.

Ví dụ

js
window.sharedStorage
  .delete("ab-testing-group")
  .then(() => console.log("Value deleted"));

Thông số kỹ thuật

Thông số kỹ thuật
Shared Storage API
# dom-sharedstorage-delete

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

Xem thêm