onUnload function not working properly
See original GitHub issuethe onUnload function triggers as soon as the new window opens up so the problem is that I have this state
const [popup, setPopUp] = useState(false);
and this button
<Button onClick={() => setPopUp(true)}>Login</Button>
{ popup && !session ? (
<NewWindow url='/SignInPage' onUnload={() => setPopUp(false)} />
) : null }
so as I click on the button the state of popup become true and the new window pops up but since the onUnload
function triggers before new window unload so the state of popup become false immediately and the popup closes but when I removed onUnload={() => setPopUp(false)}
and clicked on the button the new window opens up and the it doesn’t closes the onUnload
function should triggered after the new window unload
Issue Analytics
- State:
- Created a year ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
window.onunload is not working properly in Chrome browser ...
This code is working fine in IE and Firefox. But this code is not working in Chrome. Both the statements alert("Unload Window"); and...
Read more >Why onunload() does not work ..? - JavaScript
Hey guys, I have a small problem here the onunload event does not work on my firefox...don't know why. this was the example...
Read more >onUnload not working for me? - JavaScript - SitePoint Forums
I just can't get any OnUnload functions to work on all browsers. This is because the onunload event not supported properly (if at...
Read more >unload not working in Chrome - MSDN - Microsoft
This works fine in Firefox but not in Chrome. Am currently try ing to get it to trigger a simple alert like so:...
Read more >[Solved] JavaScript window onbeforeunload events not ...
In Crome browser window.onload = saverecords event is working but window.onbeforeunload = deleterecords event is not working.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you could use onLoad method and watch the closed value by interval created by @ilhantekir https://github.com/rmariuzzo/react-new-window/issues/109#issuecomment-1009683557
@AdityaKirad which browser and React version are you using?