-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Document PopStateEvent() and PopStateEvent.state #25702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f7db37c
Document PopStateEvent() and PopStateEvent.state
teoli2003 4524833
Fix group
teoli2003 1f414ec
Update files/en-us/web/api/history_api/example/index.md
teoli2003 a6cad93
Update files/en-us/web/api/history_api/index.md
teoli2003 2b030de
Update files/en-us/web/api/history_api/index.md
teoli2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.