進入網頁開始計時,關閉頁面時觸發操作事件

來源:互聯網
上載者:User

標籤:logs   ecs   onsubmit   clock   oat   ==   rip   out   cloc   

<html><head>    <title>頁面停留時間</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;        var s_secs_spent;        var s_mins_spent;        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_now.getTime() - 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);            s_secs_spent = "" + ((i_secs_spent > 9) ? i_secs_spent : "0" + i_secs_spent);            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);        }        window.onbeforeunload = onbeforeunload_handler;        window.onunload = onunload_handler;        function onbeforeunload_handler() {            var show = s_mins_spent + ":" + s_secs_spent;            //Do SomeThing        }        function onunload_handler() {            var show = s_mins_spent + ":" + s_secs_spent;            //Do SomeThing         }       </script>    <form name="fm0" onsubmit="0">    <font color="#888888" size="-1">您在本網頁的停留時間:</font>    <input type="text" name="time_spent" size="7" onfocus="this.blur()">    </form></body></html>
頁面跳轉觸發事件:

onbeforeunload
onunload 
 

進入網頁開始計時,關閉頁面時觸發操作事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.