Close new window on parent tab close.
rodrigo-i-sosa opened this issue · comments
Rodrigo Sosa commented
Is there a way to implement this behavior? currently the only way to close the window is by closing the browser completely.
Rubens Mariuzzo commented
Hey there! I apologize for the very long reply. Currently, you can handle using the onOpen
callback to capture the window instance.
Here's a simplified example:
const [popup, setPopup] = useState()
useEffect(() => {
window.addEventListener('unload', () => {
if (popup) popup.close()
})
}, [])
return <NewWindow onOpen={e => setPopup(e)} />