frame_recursive_target.html (883B)
1 <!DOCTYPE html> 2 <iframe id="static"></iframe> 3 <script> 4 const name = "frame_recursive_target"; 5 const url = location.href; 6 const iframe = document.querySelector("iframe"); 7 let isCrossOrigin = false; 8 try { 9 window.parent.location.hostname; 10 } catch (_) { 11 isCrossOrigin = true; 12 } 13 14 addEventListener("load", async () => { 15 await new Promise(resolve => { 16 iframe.addEventListener("load", resolve); 17 if (!isCrossOrigin) { 18 iframe.name = name; 19 } 20 21 iframe.src = url; 22 }); 23 24 if (isCrossOrigin) { 25 const innerWin = iframe.contentWindow.document.querySelector("iframe"); 26 await new Promise(resolve => { 27 innerWin.addEventListener("load", resolve); 28 window.open(url, name); 29 }); 30 } 31 }); 32 </script>