Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document PopStateEvent() and PopStateEvent.state (#25702)
Co-authored-by: dawei-wang <dawei-wang@users.noreply.github.com>
- Loading branch information
1 parent
68421bd
commit 55de680
Showing
16 changed files
with
155 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
title: PopStateEvent() | ||
slug: Web/API/PopStateEvent/PopStateEvent | ||
page-type: web-api-constructor | ||
browser-compat: api.PopStateEvent.PopStateEvent | ||
--- | ||
|
||
{{APIRef("History API")}} | ||
|
||
The **`PopStateEvent()`** constructor creates a new {{domxref("PopStateEvent")}} object. | ||
|
||
> **Note:** A web developer doesn't typically need to call this constructor, as the browser creates these objects itself when firing {{domxref("Window/popstate_event", "popstate")}} events. | ||
## Syntax | ||
|
||
```js-nolint | ||
new PopStateEvent(type, options) | ||
``` | ||
|
||
### Parameters | ||
|
||
- `type` | ||
- : A string with the name of the event. | ||
It is case-sensitive and browsers set it to `popstate`. | ||
- `options` {{optional_inline}} | ||
- : An object that, _in addition to the properties defined in {{domxref("Event/Event", "Event()")}}_, has the following property: | ||
- `state` {{optional_inline}} | ||
- : An object representing the state. Practically it is a value provided by the call to {{domxref("history.pushState()")}} or {{domxref("history.replaceState()")}}. If not set, it defaults to `null`. | ||
|
||
### Return value | ||
|
||
A new {{domxref("PopStateEvent")}} object. | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("history.pushState()")}} | ||
- {{domxref("history.replaceState()")}} | ||
- {{domxref("Window/popstate_event", "popstate")}} event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
title: PopStateEvent.state | ||
slug: Web/API/PopStateEvent/state | ||
page-type: web-api-instance-property | ||
browser-compat: api.PopStateEvent.state | ||
--- | ||
|
||
{{ APIRef("History API") }} | ||
|
||
The **`state`** read-only property of the {{domxref("PopStateEvent")}} interface represents the state stored when the event was created. | ||
|
||
Practically it is a value provided by the call to {{domxref("history.pushState()")}} or {{domxref("history.replaceState()")}} | ||
|
||
## Value | ||
|
||
An object, or `null`. | ||
|
||
## Examples | ||
|
||
The code below logs the value of `state` when using the | ||
{{domxref("History.pushState","pushState()")}} method to push a value to the history. | ||
|
||
```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" | ||
); | ||
``` | ||
|
||
This will log: | ||
|
||
```plain | ||
State received: { name: "Example" } | ||
State received: { name: "Another example" } | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- {{domxref("PopStateEvent()")}} constructor | ||
- {{domxref("History.state")}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.