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
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ệ
Promisetừ chối vớiTypeErrornế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).
keyvượ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,Promisetừ chối vớiTypeErrornếu:- Module worklet chưa được thêm bằng
SharedStorageWorklet.addModule().
- Module worklet chưa được thêm bằng
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ụ
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> |