Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
455 views
in Technique[技术] by (71.8m points)

onbeforeunload - beforeunload Event in ReactJS Not Working on Server

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...