How can I use javascript to record how long the user stays on the page?
给我你的怀抱
给我你的怀抱 2017-05-19 10:40:39
0
1
518

I want to write a js that counts how long users stay on the page. There are currently two methods, but neither is ideal.

  1. Timer, use ajax to send data to the database at certain intervals. This method cannot guarantee accuracy and will affect efficiency

  2. Use the onunload event to send data when the user closes the window. However, a dialog box will pop up in chrome to prompt whether to leave the page, which is very unfriendly to users visiting the website

How to solve it

给我你的怀抱
给我你的怀抱

reply all(1)
滿天的星座

If you want to be very accurate, you can consider using websocketto maintain a long connection with the backend?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template