Favorites

HTML onpageswap Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onpageswap
HTML Event AttributeThis event attribute is supported in some modern browsers, but not all.
Updated 22nd November 2026

Description

The onpageswap event attribute is used on the <body> element (or as window.onpageswap) and runs a script when a document is about to be unloaded because of a navigation to another document, just before the last frame of the old page is captured.

It is mainly used with cross-document view transitions: event.viewTransition holds the outgoing ViewTransition (or null), and event.activation describes the navigation, including the destination entry, so the old page can set view-transition-name on the element that should animate. Its counterpart on the new page is onpagereveal.

Syntax

<body onpageswap="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onpageswap event</title>
</head>
<body>
<p>Click the link and watch the console:</p>
<a href="?next">Go to next page</a>
<script>
window.onpageswap = function (event) {
console.log("pageswap fired. View transition: " + (event.viewTransition ? "yes" : "none"));
};
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onpageswap event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee