iframe-parent.html (1201B)
1 <!DOCTYPE html> 2 <title>Helper IFrame</title> 3 <script> 4 'use strict'; 5 6 async function onLoad() { 7 // Nested Step 5: wpt/web-locks/partitioned-web-locks.tentative.https.html 8 // Load the innermost child iframe and its content. 9 const params = new URLSearchParams(self.location.search); 10 const frame = document.createElement('iframe'); 11 frame.src = params.get('target'); 12 document.body.appendChild(frame); 13 14 self.addEventListener('message', evt => { 15 // Nested Step 6: wpt/web-locks/partitioned-web-locks.tentative.https.html 16 // Pass any operations request messages to the 17 // innermost child iframe. 18 if (evt.data.op){ 19 // Ensure that the iframe has loaded before passing 20 // on the message. 21 frame.addEventListener('load', function(){ 22 frame.contentWindow.postMessage(evt.data, '*'); 23 }); 24 } 25 // Nested Step 8: wpt/web-locks/partitioned-web-locks.tentative.https.html 26 else { 27 // All other messages, should be sent back to the 28 // top-level site. 29 if (self.opener) 30 self.opener.postMessage(evt.data, '*'); 31 else 32 self.top.postMessage(evt.data, '*'); 33 } 34 }); 35 } 36 self.addEventListener('load', onLoad); 37 </script>