Javascript 10分钟不活动后显示弹出窗口

Javascript 10分钟不活动后显示弹出窗口,javascript,time,popup,Javascript,Time,Popup,你好, 找不到代码:x是否有人可以发布,或解释如何在10分钟不活动后弹出 当页面加载10分钟后,成员处于非活动状态时,成员将获得一个带有一些按钮和文本的弹出窗口 <div> <p>Away from keyboard?</p> <ul class="button"> <li><a href="#0">I'm Back!</a></li> </ul>

你好, 找不到代码:x是否有人可以发布,或解释如何在10分钟不活动后弹出

当页面加载10分钟后,成员处于非活动状态时,成员将获得一个带有一些按钮和文本的弹出窗口

<div>
    <p>Away from keyboard?</p>
    <ul class="button">
        <li><a href="#0">I'm Back!</a></li>
    </ul>
</div>

远离键盘

这基本上是每秒钟运行一次——如果是第600秒,它会在运行代码后退出


将事件与
设置超时
方法一起附加到
文档
对象以显示弹出窗口。一种方法是

var popupTimer,
        TIME_OUT = 600;

// function that displays the popup
function displayPopup() {
    // display the popup here
}

// Set the timeout to display the popup
popupTimer = setTimeout(displayPopup, TIME_OUT);

// attch events to the document object
// you can add more events here based on
// what events you want to track
$(document).on('click change keypress', function() {

  // clear the timeout whenever the event is handled
  clearTimeout(popupTimer);

  // Reset the timer
  popupTimer = setTimeout(displayPopup, TIME_OUT);
});

也许可以尝试这里提供的解决方案,但不检查用户是否空闲。您必须监视鼠标/键盘。@当用户进行有意义的交互时,页面所有者Ilya应该能够将秒数设置为0。有时你不想太笼统地这样做。这不符合OP的要求,“10分钟不活动后”,所以我建议你让OP知道这一点,或者用便条更新你的答案。@Ilya和Franco你完全正确。添加了空闲检查器。
var popupTimer,
        TIME_OUT = 600;

// function that displays the popup
function displayPopup() {
    // display the popup here
}

// Set the timeout to display the popup
popupTimer = setTimeout(displayPopup, TIME_OUT);

// attch events to the document object
// you can add more events here based on
// what events you want to track
$(document).on('click change keypress', function() {

  // clear the timeout whenever the event is handled
  clearTimeout(popupTimer);

  // Reset the timer
  popupTimer = setTimeout(displayPopup, TIME_OUT);
});