zoukankan      html  css  js  c++  java
  • 进入网页开始计时,关闭页面时触发操作事件

    <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 
     
  • 相关阅读:
    Pikachu漏洞平台---XSS(Cross-Site Scripting) 跨站脚本
    Pikachu漏洞练习平台(暴力破解模块)
    DVWA-- 不安全得验证码Insecure CAPTCHA
    DVWA-文件上传 File Upload
    DVWA之CSRF(跨站请求伪造)
    绑定方法与非绑定方法
    XML,面向对象基础
    configparser ,subprocess , xlrd ,xlwt 模块
    logging ,re 模块
    random,json,pickle,hashlib,shutil,hmac,shelve 模块
  • 原文地址:https://www.cnblogs.com/byfcumt/p/7058175.html
Copyright © 2011-2022 走看看