message-opener.html (636B)
1 <script> 2 /** 3 * Send a message to the opening browsing context when the document is 4 * "completely loaded" (a condition which occurs immediately after the `load` 5 * and `pageshow` events are fired). 6 * https://html.spec.whatwg.org/multipage/parsing.html#the-end 7 */ 8 'use strict'; 9 10 // The `pageshow` event is used instead of the `load` event because this 11 // document may itself be accessed via history traversal. In such cases, the 12 // browser may choose to reuse a cached document and therefore fire no 13 // additional `load` events. 14 addEventListener('pageshow', () => { 15 setTimeout(() => opener.postMessage(null, '*'), 0); 16 }); 17 </script>