PopStateEvent: state property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thuộc tính chỉ đọc state của giao diện PopStateEvent đại diện cho trạng thái được lưu trữ khi sự kiện được tạo.
Thực tế là giá trị được cung cấp bởi lệnh gọi history.pushState() hoặc history.replaceState().
Giá trị
Một đối tượng hoặc null.
Ví dụ
Code bên dưới ghi log giá trị của state khi sử dụng phương thức pushState() để đẩy giá trị vào lịch sử.
js
// Log the state of
addEventListener("popstate", (event) => {
console.log("State received: ", event.state);
});
// Now push something on the stack
history.pushState({ name: "Example" }, "pushState example", "page1.html");
history.pushState(
{ name: "Another example" },
"pushState example",
"page1.html",
);
Kết quả sẽ ghi log:
State received: { name: "Example" }
State received: { name: "Another example" }
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| HTML> # dom-popstateevent-state-dev> |
Tương thích trình duyệt
Xem thêm
- Hàm khởi tạo
PopStateEvent() History.state