1. 7.6 Browsing the Web
      1. 7.6.1 History traversal
        1. 7.6.1.1 Persisted user state restoration
        2. 7.6.1.2 The PopStateEvent interface
        3. 7.6.1.3 The HashChangeEvent interface
        4. 7.6.1.4 The PageTransitionEvent interface
      2. 7.6.2 Unloading documents
        1. 7.6.2.1 The BeforeUnloadEvent interface

7.6 Browsing the Web

7.6.1 History traversal

7.6.1.1 Persisted user state restoration

This can even include updating the dir attribute of textarea elements or input elements whose type attribute is in either the Text state or the Search state, if the persisted state includes the directionality of user input in such controls.

Not restoring the scroll position by user agent does not imply that the scroll position will be left at any particular value (e.g., (0,0)). The actual scroll position depends on the navigation type and the user agent's particular caching strategy. So web applications cannot assume any particular scroll position but rather are urged to set it to what they want it to be.

7.6.1.2 The PopStateEvent interface
[Exposed=Window,
 Constructor(DOMString type, optional PopStateEventInit eventInitDict)]
interface PopStateEvent : Event {
  readonly attribute any state;
};

dictionary PopStateEventInit : EventInit {
  any state = null;
};
event . state

Returns a copy of the information that was provided to pushState() or replaceState().

7.6.1.3 The HashChangeEvent interface

Support: hashchangeChrome for Android 67+Chrome 5+iOS Safari 4.0+UC Browser for Android 11.8+Firefox 3.6+IE 8+Opera Mini NoneSafari 5+Edge 12+Samsung Internet 4+Android Browser 2.2+Opera 10.6+

Source: caniuse.com

[Exposed=Window,
 Constructor(DOMString type, optional HashChangeEventInit eventInitDict)]
interface HashChangeEvent : Event {
  readonly attribute USVString oldURL;
  readonly attribute USVString newURL;
};

dictionary HashChangeEventInit : EventInit {
  USVString oldURL = "";
  USVString newURL = "";
};
event . oldURL

Returns the URL of the session history entry that was previously current.

event . newURL

Returns the URL of the session history entry that is now current.

7.6.1.4 The PageTransitionEvent interface
[Exposed=Window,
 Constructor(DOMString type, optional PageTransitionEventInit eventInitDict)]
interface PageTransitionEvent : Event {
  readonly attribute boolean persisted;
};

dictionary PageTransitionEventInit : EventInit {
  boolean persisted = false;
};
event . persisted

For the pageshow event, returns false if the page is newly being loaded (and the load event will fire). Otherwise, returns true.

For the pagehide event, returns false if the page is going away for the last time. Otherwise, returns true, meaning that (if nothing conspires to make the page unsalvageable) the page might be reused if the user navigates back to this page.

Things that can cause the page to be unsalvageable include:

7.6.2 Unloading documents

7.6.2.1 The BeforeUnloadEvent interface
[Exposed=Window]
interface BeforeUnloadEvent : Event {
  attribute DOMString returnValue;
};

There are no BeforeUnloadEvent-specific initialization methods.

The BeforeUnloadEvent interface is a legacy interface which allows prompting to unload to be controlled not only by canceling the event, but by setting the returnValue attribute to a value besides the empty string. Authors should use the preventDefault() method, or other means of canceling events, instead of using returnValue.