PushMessageData: phương thức json()
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 only available in Service Workers.
Phương thức json() của giao diện PushMessageData trích xuất dữ liệu push message bằng cách phân tích nó như một chuỗi JSON và trả về kết quả.
Cú pháp
js
json()
Tham số
Không có.
Giá trị trả về
Kết quả của việc phân tích dữ liệu sự kiện push dưới dạng JSON. Giá trị này có thể là bất cứ thứ gì có thể biểu diễn bằng JSON - object, mảng, chuỗi, số...
Ví dụ
js
self.addEventListener("push", (event) => {
const myData = event.data.json();
// làm gì đó với dữ liệu của bạn
});
Thông số kỹ thuật
| Specification |
|---|
| Push API> # dom-pushmessagedata-json> |