On my website, I am trying to count (and display) how many seconds (not minutes or hours) the user has been on my site. So, if they have been on it for 5 minutes, it will display 300, Not 5 minutes. I am Very Unexperienced with JavaScript, So please help.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
You can use the
setInterval
function to run another function as often as you choose. For example:If you run this snippet, you'll see the counter working.
The
setInterval
function takes two parameters:Since you want to call increment the counter every second, you want to use 1000 milliseconds (1 second).
For more details, see the MDN documentation for
setInterval
.My answer is similar to the one above but I'll give it anyway. This will only work on a single page so hopefully your site already runs on AJAX.