resource-popup.html (653B)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <meta charset="utf-8"> 4 <title></title> 5 <script> 6 'use strict'; 7 const params = new URL(location).searchParams; 8 const bc = new BroadcastChannel(params.get('channel_name')); 9 const win = open(params.get('resource'), params.get('resource_name')); 10 11 bc.onmessage = () => { 12 win.close(); 13 close(); 14 }; 15 const id = setInterval(() => { 16 if (win.closed || win.location.href !== 'about:blank') { 17 clearInterval(id); 18 const winName = (() => { 19 try { 20 return win.name; 21 } catch (e) { 22 return null; 23 } 24 })(); 25 bc.postMessage({name: winName || null, closed: win.closed}); 26 } 27 }, 100); 28 </script>