This article introduces how to use JavaScript to display the stay time on the browser status bar, that is, display the visitor's stay time on this page on the status bar. Problem description: display on the status bar, visitor's stay on this page (for example, you stayed on this page (for example, you stayed on this page for X hours X minutes X seconds)
This problem is equivalent to designing a timer to show how long a viewer has stayed on the page. There are two methods to solve this problem.
Method 1: Use the system time. That is, set a variable to get the logon start time startTime, and then use the setTimeout () function to refresh the page continuously. At the same time, get the nowTime of the current time, then, the current time minus the logon start time is the stay time. I will not write it in detail here. The following method 2 is used for implementation.
Method 2: set three variables: second, minute, and hour. Then let second continue to + 1, and use setTimeout to refresh the page every second. When second is greater than or equal to 60, minute starts to + 1 and second is reset to zero. Similarly, when minute is greater than or equal to 60, hour starts to + 1. In this way, the timing function can be implemented.
Method 2 code:
The Code is as follows:
Untitled document