Summary of several examples of page stay time displayed in javascript

Source: Internet
Author: User

Sometimes we can see that some websites can record the access time when you enter the website and leave the website. Below I will use js to write a few simple methods, for your reference.

Instance 1

The Code is as follows: Copy code

<Script type = "text/javascript">
Var second = 0;
Var minute = 0;
Var hour = 0;
Window. setInterval ("OnlineStayTime ();", 1000 );
Function OnlineStayTime (){
Second ++;
If (second = 60 ){
Second = 0;
Minute ++;
}
If (minute = 60 ){
Minute = 0;
Hour ++;
}
Window. status = "stay time" + hour + ":" + minute + ":" + second;
}
</Script>

Instance 2

The Code is as follows: Copy code

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312">
<Title> JavaScript timer </Title>
<H3> <Font color = "blue"> topic: JavaScript timer </Font> </H3>
</Head>

<Body>
<Form name = "fm_Time" onSubmit = "0">
<Font size = 5 color = "red"> <center> show your stay time </Center> </Font> <P>
<HR size = 3 color = "blue">
Current Time: <P>
<Input type = "text" name = "t_spent" id = "t_spent" size = 7>
</Form> <BR>
</HTML>
<Script language = "javascript">
Var time = 1;
Function show_secs (){
Document. getElementById ('t_ spent'). value = time + 'second ';
Time ++;
Window. setTimeout ('show _ secs () ', 1000 );
}
Show_secs ();
</Script>

Instance 3

 

The Code is as follows: Copy code
 
<Html>
<Head>
<Title> statistical method of page stay time </title>
</Head>
<BODY onLoad = "init (); window. setTimeout ('show _ secs () ', 1);">
<Script language = "JAVASCRIPT">
<! --
Var ap_name = navigator. appName;
Var ap_vinfo = navigator. appVersion;
Var ap_ver = parseFloat (ap_vinfo.substring (0, ap_vinfo.indexOf ('(')));
Var time_start = new Date ();
Var clock_start = time_start.getTime ();
Var dl_ OK = false;
Function init ()
{
If (ap_name = "Netscape" & ap_ver >=3.0)
Dl_ OK = true;
Return true;
}
Function get_time_spent ()
{
Var time_now = new Date ();
Return (time_notesgettime ()-clock_start)/1000 );
}
Function show_secs ()
{
Var I _total_secs = Math. round (get_time_spent ());
Var I _secs_spent = I _total_secs % 60;
Var I _mins_spent = Math. round (I _total_secs-30)/60 );
Var s_secs_spent = "" + (I _secs_spent> 9 )? I _secs_spent: "0" + I _secs_spent );
Var s_mins_spent = "" + (I _mins_spent> 9 )? I _mins_spent: "0" + I _mins_spent );
Document. fm0.time _ spent. value = s_mins_spent + ":" + s_secs_spent;
Window. setTimeout ('show _ secs () ', 1000 );
}
// -->
</SCRIPT>
<Form name = "fm0" onSubmit = "0"> your stay on this page:
<INPUT type = "text" name = "time_spent" size = 7 onFocus = "this. blur ()">
</Form>
</Body>
</Html>

Related Article

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.