Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The prerenderingchange
event is fired on a prerendered document when it is activated (i.e. the user views the page).
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The prerenderingchange
event is fired on a prerendered document when it is activated (i.e. the user views the page).
Use the event name in methods like addEventListener()
, or set an event handler property.
js
addEventListener("prerenderingchange", (event) => {}); prerenderingchange = (event) => {};
A generic Event
.
The following code sets up an event listener to run a function once prerendering has finished, on a prerendered page (the prerendering is detected via Document.prerendering
), or runs it immediately on a non-prerendered page:
js
if (document.prerendering) { document.addEventListener("prerenderingchange", initAnalytics, { once: true, }); } else { initAnalytics(); }
Note: See the Speculation Rules API landing page and particularly the Unsafe speculative loading conditions section for more information on the kinds of activities you might wish to delay until after prerendering has finished.
Specification |
---|
Prerendering Revamped # eventdef-document-prerenderingchange |
Prerendering Revamped # dom-document-onprerenderingchange |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
prerenderingchange_event |
108 | 108 | No | No | 94 | No | 108 | 108 | No | 73 | No | 21.0 |
prerendering
property
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/prerenderingchange_event