无用户操作后自动重定向 [英] auto redirect after no user action

查看:75
本文介绍了无用户操作后自动重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

T-mobile已经使用了这种逻辑,但我不知道该怎么做。

这是这种情况::我登录到我的网站后,在2分钟内什么都没做,只是坐在屏幕上。在这种情况下,我应该重定向到注销会话的会话将被注销。

This is the scenario: I login to my website and don't do anything at all for 2 minutes, just sit and look at the screen. In such case, I should be redirected to logout page where session will be destroyed.

我该怎么做?

网络上的示例基于用户操作,例如在用户活动后检查某事(上次活动等)

Examples on web are based on user actions such as check something (last activity etc.) after user activity.

注意:正在使用Codeigniter及其数据库会话。

Note: I'm using Codeigniter and its database sessions.

推荐答案

您需要使用javascript:

You need javascript:

<script type="text/javascript">
setTimeout(onUserInactivity, 1000 * 120)
function onUserInactivity() {
   window.location.href = "onUserInactivity.php"
}
</script>

这将在2分钟无活动后重定向用户。如果要使其依赖于鼠标移动,请尝试:

This will redirect the user after 2 Minutes of inactivity. If you want to make it dependend of the mouse-moving, try:

<script type="text/javascript">
inactivityTimeout = False
resetTimeout()
function onUserInactivity() {
   window.location.href = "onUserInactivity.php"
}
function resetTimeout() {
   clearTimeout(inactivityTimeout)
   inactivityTimeout = setTimeout(onUserInactivity, 1000 * 120)
}
window.onmousemove = resetTimeout
</script>

这篇关于无用户操作后自动重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆