Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

onpagereveal — handling page reveal

The onpagereveal attribute on body sets the handler for the Window object's pagereveal event. The event occurs when the document begins rendering after initialization or reactivation.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<body onpagereveal="JavaScript statements">

onpagereveal is an event handler attribute placed on body. Its value contains JavaScript statements, not an event name. Although written on body, it handles the Window object's pagereveal event, not a local event on that element.

The browser fires pagereveal once per document activation: during initial rendering and after reactivation. It is not a per-frame event or a replacement for load. The browser may display a previously cached frame beforehand, so the handler is not guaranteed to run before any page pixels appear.

The event object is a PageRevealEvent. Its viewTransition references the associated cross-document transition or is null; the event itself does not require a transition animation. Alternatives to the attribute are window.onpagereveal = handler and window.addEventListener('pagereveal', handler).

When the example's handler runs, it writes event.type (pagereveal) to the body element's data-received attribute via document.body.dataset.received. It does not change visible text. The two true values in the shown console output indicate that body has the onpagereveal attribute and that window exposes an onpagereveal property. They do not confirm that the handler ran. For the handler to run, the browser must implement the event and allow inline event handlers to execute; a security policy may block them.

Examples

<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Body onpagereveal handler</title></head>
<body onpagereveal="document.body.dataset.received = event.type">
  <script>
    console.log('onpagereveal attribute present: ' + document.body.hasAttribute('onpagereveal'));
    console.log('onpagereveal event property available: ' + ('onpagereveal' in window));
  </script>
</body>
</html>

Result

onpagereveal attribute present: true
onpagereveal event property available: true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources