question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onUnload function not working properly

See original GitHub issue

the 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:open
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ilhamgumcommented, Nov 22, 2022

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

0reactions
rmariuzzocommented, Nov 26, 2022

@AdityaKirad which browser and React version are you using?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found