获取iframe对话框里边的body的点击事件,各种监听页面活动的方法,检测用户是否活跃的方法


// 检测用户活跃情况
function isActive() {
    var arr = ['index', 'login']
    var result = arr.some(function (item) {
        return window.location.href.indexOf(item) > 0
    })
    // result 表示当前页面可能是index或者注册页面 
    // 不是index页面 ,不是注册页面才会去检测用户的活跃状态(鼠标移动状态)
    if (!result) {
        window.lastTime = new Date().getTime();
        window.currentTime = new Date().getTime();
        //设置超时时间: 10分
        window.timeOut = 10 * 60 * 1000;
        //设置监听时间: 1分钟
        window.listenTime = 1 * 60 * 1000;

        window.onload = function () {
            /* 检测鼠标移动事件 */
            document.addEventListener('mousemove', function () {
                // 更新最后的操作时间
              
                window.lastTime = new Date().getTime();

              
                console.log('鼠标移动了---------------lastTime------' + window.lastTime + "-------------currentTime----------" + window.currentTime + "-----相减时间---------" + (window.currentTime - window.lastTime))

            })
            window.addEventListener('focus', function () {
                // 更新最后的操作时间
               
                window.lastTime = new Date().getTime();
                console.log('获得焦点了---------------lastTime------' + window.lastTime + "-------------currentTime----------" + window.currentTime + "-----相减时间---------" + (window.currentTime - window.lastTime))
            })
            window.addEventListener('blur', function () {
                // 更新最后的操作时间
              
                window.lastTime = new Date().getTime();
                console.log('市区---------------lastTime------' + window.lastTime + "-------------currentTime----------" + window.currentTime + "-----相减时间---------" + (window.currentTime - window.lastTime))
            })
            window.addEventListener('click', function () {
                // 更新最后的操作时间

                window.lastTime = new Date().getTime();
                console.log('点击---------------lastTime------' + window.lastTime + "-------------currentTime----------" + window.currentTime + "-----相减时间---------" + (window.currentTime - window.lastTime))
            })
//检测页面是否在主线程页面, hidden 表示当前页面切换为隐藏状态,visible表示当前页面切换为浏览状态
            document.addEventListener('visibilitychange', function () {
                // 更新最后的操作时间
                window.stateww = document.visibilityState;
                window.lastTime = new Date().getTime();
       
              
            })

          
           
        }

        /* 定时器  间隔1分钟,检测是否长时间未操作页面  */
        window.quitTime = window.setInterval(window.testTime, window.listenTime);

        
    }
}
// 超时函数
function testTime() {
    //更新当前时间
    window.currentTime = new Date().getTime();
    console.log('currentTime', currentTime)
    //判断是否超时
    if ((window.currentTime - window.lastTime > window.timeOut)) {
        // 清除掉定时器
        window.clearInterval(window.quitTime);
        // 超时操作
        Loading(true, "正在强制注销系统...");
        window.setTimeout(function () {
            GetAjax("/Login/OutLogin", "", function (data) {
              
                window.location.href = '../login/index';
            });
        }, 200);

    }


    window.inputChange2 = document.getElementsByName("dialogFrame")[0].contentWindow.document.querySelector("body")//获取inputDom
    console.log(window.inputChange2);
    window.inputChange2.addEventListener("click", function () {
        window.lastTime = new Date().getTime();
        console.log('ifram里边的内容对话框---------------lastTime------' + window.lastTime + "-------------currentTime----------" + window.currentTime + "-----相减时间---------" +     (window.currentTime - window.lastTime))

    })


}
<div class="panel window" style="display: block; width: 1188px; left: 360px; top: 110px; z-index: 9002;"><div class="panel-header panel-header-noborder window-header" style="width: 1188px;"><div class="panel-title">检出限</div><div class="panel-tool"><a href="javascript:void(0)" class="panel-tool-close"></a></div></div><div id="dd" style="width: 1186px; height: 714px;" title="" class="panel-body panel-body-noborder window-body">
<iframe name="dialogFrame" scrolling="no" frameborder="0" src="/ElementalRecord/DetectionLimit?psInspectType=1&amp;psId=13dfbbc4-62ec-4fc8-bb15-1b7cc160342e" style="width:100%;height:95%;"></iframe></div></div>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值