其实,并没有太大的用途,只是,我今天碰到的这个客户太奇怪而已,所以,必须用到这种方法。只写两个函数,一个是用户在线时间函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<span style="color: #339933"><</span>BODY <span style="color: #000066">onLoad</span><span style="color: #339933">=</span><span style="color: #3366CC">"init(); window.setTimeout('show_secs()',1);"</span><span style="color: #339933">></span>
<span style="color: #339933"><</span>SCRIPT LANGUAGE<span style="color: #339933">=</span><span style="color: #3366CC">"JAVASCRIPT"</span><span style="color: #339933">></span>
 
<span style="color: #339933"><!--</span>
<span style="color: #003366;font-weight: bold">var</span> ap_name <span style="color: #339933">=</span> navigator.<span style="color: #660066">appName</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> ap_vinfo <span style="color: #339933">=</span> navigator.<span style="color: #660066">appVersion</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> ap_ver <span style="color: #339933">=</span> parseFloat<span style="color: #009900">(</span>ap_vinfo.<span style="color: #660066">substring</span><span style="color: #009900">(</span><span style="color: #CC0000">0</span><span style="color: #339933">,</span>ap_vinfo.<span style="color: #660066">indexOf</span><span style="color: #009900">(</span><span style="color: #3366CC">'('</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> time_start <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Date<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> clock_start <span style="color: #339933">=</span> time_start.<span style="color: #660066">getTime</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> dl_ok<span style="color: #339933">=</span><span style="color: #003366;font-weight: bold">false</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">function</span> init <span style="color: #009900">(</span><span style="color: #009900">)</span>
<span style="color: #009900">{</span>
<span style="color: #000066;font-weight: bold">if</span><span style="color: #009900">(</span>ap_name<span style="color: #339933">==</span><span style="color: #3366CC">"Netscape"</span> <span style="color: #339933">&&</span> ap_ver<span style="color: #339933">>=</span><span style="color: #CC0000">3.0</span><span style="color: #009900">)</span>
dl_ok<span style="color: #339933">=</span><span style="color: #003366;font-weight: bold">true</span><span style="color: #339933">;</span> 
<span style="color: #000066;font-weight: bold">return</span> <span style="color: #003366;font-weight: bold">true</span><span style="color: #339933">;</span>
<span style="color: #009900">}</span>
<span style="color: #003366;font-weight: bold">function</span> get_time_spent <span style="color: #009900">(</span><span style="color: #009900">)</span>
<span style="color: #009900">{</span>
<span style="color: #003366;font-weight: bold">var</span> time_now <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Date<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066;font-weight: bold">return</span><span style="color: #009900">(</span><span style="color: #009900">(</span>time_now.<span style="color: #660066">getTime</span><span style="color: #009900">(</span><span style="color: #009900">)</span> <span style="color: #339933">-</span> clock_start<span style="color: #009900">)</span><span style="color: #339933">/</span><span style="color: #CC0000">1000</span><span style="color: #009900">)</span><span style="color: #339933">;</span> 
<span style="color: #009900">}</span>
 
<span style="color: #003366;font-weight: bold">function</span> show_secs <span style="color: #009900">(</span><span style="color: #009900">)</span>
<span style="color: #009900">{</span> 
 
<span style="color: #003366;font-weight: bold">var</span> time_now <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Date<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> i_total_secs <span style="color: #339933">=</span> Math.<span style="color: #660066">round</span><span style="color: #009900">(</span>get_time_spent<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #009900">)</span><span style="color: #339933">;</span> 
<span style="color: #003366;font-weight: bold">var</span> i_secs_spent <span style="color: #339933">=</span> i_total_secs <span style="color: #339933">%</span> <span style="color: #CC0000">60</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> i_mins_spent <span style="color: #339933">=</span> Math.<span style="color: #660066">round</span><span style="color: #009900">(</span><span style="color: #009900">(</span>i_total_secs<span style="color: #339933">-</span><span style="color: #CC0000">30</span><span style="color: #009900">)</span><span style="color: #339933">/</span><span style="color: #CC0000">60</span><span style="color: #009900">)</span><span style="color: #339933">;</span> 
<span style="color: #003366;font-weight: bold">var</span> s_secs_spent <span style="color: #339933">=</span> <span style="color: #3366CC">""</span> <span style="color: #339933">+</span> <span style="color: #009900">(</span><span style="color: #009900">(</span>i_secs_spent<span style="color: #339933">></span><span style="color: #CC0000">9</span><span style="color: #009900">)</span> <span style="color: #339933">?</span> i_secs_spent <span style="color: #339933">:</span> <span style="color: #3366CC">"0"</span> <span style="color: #339933">+</span> i_secs_spent<span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #003366;font-weight: bold">var</span> s_mins_spent <span style="color: #339933">=</span><span style="color: #3366CC">""</span> <span style="color: #339933">+</span> <span style="color: #009900">(</span><span style="color: #009900">(</span>i_mins_spent<span style="color: #339933">></span><span style="color: #CC0000">9</span><span style="color: #009900">)</span> <span style="color: #339933">?</span> i_mins_spent <span style="color: #339933">:</span> <span style="color: #3366CC">"0"</span> <span style="color: #339933">+</span> i_mins_spent<span style="color: #009900">)</span><span style="color: #339933">;</span>
<span style="color: #000066;font-weight: bold">if</span><span style="color: #009900">(</span><span style="color: #009900">(</span>time_now.<span style="color: #660066">getTime</span><span style="color: #009900">(</span><span style="color: #009900">)</span> <span style="color: #339933">-</span> clock_start<span style="color: #009900">)</span><span style="color: #339933">></span><span style="color: #CC0000">35000</span><span style="color: #009900">)</span><span style="color: #009900">{</span>
	location.<span style="color: #660066">href</span><span style="color: #339933">=</span><span style="color: #3366CC">"./teethwhite.html"</span><span style="color: #339933">;</span>
	<span style="color: #009900">}</span>
 
document.<span style="color: #660066">fm0</span>.<span style="color: #660066">time_spent</span>.<span style="color: #660066">value</span> <span style="color: #339933">=</span> s_mins_spent <span style="color: #339933">+</span> <span style="color: #3366CC">":"</span> <span style="color: #339933">+</span> s_secs_spent<span style="color: #339933">;</span>
window.<span style="color: #660066">setTimeout</span><span style="color: #009900">(</span><span style="color: #3366CC">'show_secs()'</span><span style="color: #339933">,</span><span style="color: #CC0000">1000</span><span style="color: #009900">)</span><span style="color: #339933">;</span> 
<span style="color: #009900">}</span>
 
<span style="color: #339933">--></span>
 
<span style="color: #339933"></</span>SCRIPT<span style="color: #339933">></span>
<span style="color: #339933"><</span>FORM <span style="color: #000066">name</span><span style="color: #339933">=</span><span style="color: #3366CC">"fm0"</span> onSubmit<span style="color: #339933">=</span><span style="color: #3366CC">"0"</span><span style="color: #339933">><</span>FONT COLOR<span style="color: #339933">=</span><span style="color: #3366CC">"#6060FF"</span><span style="color: #339933">></span>停留时间<span style="color: #339933">:</span>
<span style="color: #339933"></</span>FONT<span style="color: #339933">><</span>INPUT type<span style="color: #339933">=</span><span style="color: #3366CC">"text"</span> <span style="color: #000066">name</span><span style="color: #339933">=</span><span style="color: #3366CC">"time_spent"</span> size<span style="color: #339933">=</span><span style="color: #CC0000">7</span> <span style="color: #000066">onFocus</span><span style="color: #339933">=</span><span style="color: #3366CC">"this.blur()"</span><span style="color: #339933">></</span>FORM<span style="color: #339933">></span>
 
<span style="color: #339933"></</span>body<span style="color: #339933">>?</span>

另一个函数,也就是清空访问时间,主要原理就是在函数内部修改JS全局变量clock_start来实现时间的清空:

1
2
3
4
5
<span style="color: #003366;font-weight: bold">function</span> qingkong<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #009900">{</span>
     <span style="color: #003366;font-weight: bold">var</span> time_start <span style="color: #339933">=</span> <span style="color: #003366;font-weight: bold">new</span> Date<span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>			   
     window.<span style="color: #660066">clock_start</span><span style="color: #339933">=</span>time_start.<span style="color: #660066">getTime</span><span style="color: #009900">(</span><span style="color: #009900">)</span><span style="color: #339933">;</span>
     window.<span style="color: #660066">setTimeout</span><span style="color: #009900">(</span><span style="color: #3366CC">'show_secs()'</span><span style="color: #339933">,</span><span style="color: #CC0000">1000</span><span style="color: #009900">)</span><span style="color: #339933">;</span>	 
<span style="color: #009900">}</span>

以上方法,大功告成,呵呵,与大家分享,不过,这经验有点太白痴,我相信大家都会了,只是我自己不会罢了,嘎嘎。