Back to Content

PageTransitionEvent

files/en-us/web/api/pagetransitionevent/index.md

latest1.1 KB
Original Source

{{APIRef("HTML DOM")}}

The PageTransitionEvent event object is available inside handler functions for the pageshow and pagehide events, fired when a document is being loaded or unloaded.

{{InheritanceDiagram}}

Constructor

  • {{domxref("PageTransitionEvent.PageTransitionEvent", "PageTransitionEvent()")}}
    • : Creates a new PageTransitionEvent object.

Instance properties

This interface also inherits properties from its parent, {{domxref("Event")}}.

  • {{domxref("PageTransitionEvent.persisted")}} {{ReadOnlyInline}}
    • : Indicates if the document is loading from a cache.

Example

js
window.addEventListener("pageshow", (event) => {
  if (event.persisted) {
    alert("The page was cached by the browser");
  } else {
    alert("The page was NOT cached by the browser");
  }
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also