Use javascript to display the visitor's stay time on this page in the browser status bar _ javascript tips-js tutorial

Source: Internet
Author: User
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.