Skip to content

History: pushState() method section-content is confusing #30014

@zjlovezj

Description

@zjlovezj

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

What specific section or headline is this issue about?

section-content

What information was incorrect, unhelpful, or incomplete?

This method is asynchronous. Add a listener for the popstate event in order to determine when the navigation has completed. The state parameter will be available in it.

What did you expect to see?

This method is asynchronous. sort of implies that the popstate event listener got a event when history.push has resolved.

And how do the user know when history.push has resolved? Or maybe it doesn't matter.

popstate event may never fired as popstate described.

I think it should made clear that history.push trigger no events, correct me if I'm wrong.

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

From blank page to abc.html, abc.html includes below js

history.pushState({a: 1}, '');
history.pushState({a: 2}, '');

If pushState without change url, at least in Chrome,

  1. click browser Back button will go back to the blank page
  2. do history.back() will stay at the abc.html and trigger a popstate event

Maybe this behavior worth a notice.

MDN metadata

Page report details

Metadata

Metadata

Assignees

No one assigned

    Labels

    Content:GlossaryGlossary entriesContent:WebAPIWeb API docseffort: smallThis task is a small effort.goal: accuracy(Experimental label) Issues about inaccurate/incorrect content.goal: clarity(Experimental label) Issues about unclear/confusing/inconcise content.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions