I have a ReactJS app in which I am using the beforeunload event to determine when a user leaves the page (either by closing the tab or the window). Code I am using is:
window.addEventListener("beforeunload", () => {
//Update active user count
});
This is to keep a live count of how many users are on a specific page for a dashboard. The page can be accessed by anyone and does not require logging in. This code works fine with I run the application locally, but once I deploy it to the server it does not run the event.
Any reason this would be fine locally but not when deployed?
question from:
https://stackoverflow.com/questions/65905078/beforeunload-event-in-reactjs-not-working-on-server 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…