- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 javascript setInterval() 来检查用户空闲时间并在自动注销前显示弹出警报。但它不适用于多个选项卡(适用于单个选项卡)
以下是我的代码:
localStorage.removeItem("idleTimeValue");
var idleInterval = setInterval(timerIncrement, 1000);
function timerIncrement()
{
if(localStorage.getItem("idleTimeValue")) {
idleTime = parseInt(localStorage.getItem("idleTimeValue")) + 1; //increments idle time by one second
} else {
idleTime = 1;
}
localStorage.setItem("idleTimeValue", idleTime);
var timeDiff = 600;
var totTimeRemaining = timeDiff-idleTime;
if(totTimeRemaining > 0) {
$('#timeoutWindow').modal('show');
var minutes = Math.floor(totTimeRemaining / 60);
var seconds = totTimeRemaining - minutes * 60;
$('#timeoutRemainingTime').html(minutes+" minutes and "+seconds+" seconds");
} else {
window.location = httpHost+"/account/index/logout";
}
}
$(this).click(function (e)
{
localStorage.removeItem("idleTimeValue");
$('#timeoutWindow').modal('hide');
});
我在 localStorage 中设置空闲时间,比如 -
localStorage.setItem("idleTimeValue", idleTime);
因此,如果我打开 3 个选项卡,setInterval() 函数将在所有选项卡中运行,idleTime 也会增加 3 秒而不是 1 秒,并且时间计算发生错误。
我需要在所有选项卡中显示弹出窗口,并且在一个选项卡中单击继续应该会反射(reflect)在所有其他选项卡中。
有人可以为此提出解决方案吗?请大家帮忙
最佳答案
谢谢大家,我找到了解决方案。
我使用了一个存储当前时间的 localStorage 值。如果 localStorage["currentTime"] 中不存在任何值,则将当前时间存储在 localStorage 中。
var currentTime = new Date();
if ( !(localStorage.getItem("currentTime")) || (localStorage.getItem("currentTime") == "") )
{
idleTime = 0;
setTimeout(function() { localStorage.setItem("currentTime", currentTime)},5000); // current time is set to localStorage after seconds (it is for setting in multiple tabs)
}
显示超时弹出窗口的所有计算都是使用 localStorage.getItem("currentTime") 值完成的。
然后如果用户不空闲(当用户点击某处时),我将 localStorage["currentTime"] 设置为 null
$(this).click(function (e)
{
$('#timeoutWindow').modal('hide');
localStorage.setItem("currentTime", "");
idleTime = 0;
});
关于带有多个选项卡弹出警报的 Javascript session 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26993567/
我是 Java 新手,我遇到了这个我无法解决的问题。我继承了这个项目,并且我的 scriptlet 之一中有以下代码: DefaultLogger.logMessage("DEBUG path: "+
在做web应用的自动化测试时,定位元素是必不可少的,这个过程经常会碰到定位不到元素的情况(报selenium.common.exceptions.NoSuchElementException),一般
我之前已经这样做过,但令我惊讶的是 CListCtrl 不会以颜色显示文本。我在对话框上有 ListView 控件。我正在使用 VS2010,是否还缺少其他东西? void CGameView::On
我正在尝试计算 4 个表中每个学生的 GPA: Student(STUDENT_ID, STUDENT_LNAME, STUDENT_FNAME, MAJOR) Course(COURSE_NO, C
当我在 windows 和 mac 上使用 jasper 报告时它工作正常,当我将我的应用程序部署到 linux 机器 并尝试生成它抛出的报告时 net.sf.jasperreports.engine
我正在构建 iOS 应用并尝试实现应用内购买(非消费品)。 所有 bundle ID 等都已设置并正常工作,当我获取 Apple Store 服务器时,我可以看到我的产品有效。但是,在测试时,我在 p
我正在尝试使用非固定字符数组读取用户输入,但当我在键盘上输入内容时它只是软崩溃(没有崩溃窗口)。当我在在线 C 编译器上运行它时,它说 Segmentation fault (core dumped)
事实: 无根 podman 非常适合 uid 1480 无根 podman 为 uid 2088 失败 中央操作系统 7 内核 3.10.0-1062.1.2.el7.x86_64 podman 版本
根据 homebrew-brew 官方的解释得知,MongoDB 不再是开源的了,并且已经从 Homebrew中移除 #43770 正是由于 MongoDB 的商业化不太理想,所以它选择了闭源。所
我用命令禁用collectstatic heroku config:set DISABLE_COLLECTSTATIC=1 成功将我的项目推送到 Heroku 后,手动 collectstatic 如
代码如下: public class TryStuffOutHere { public static void main(String[] args) {
我已经设置了我的 redis 服务器,以便 CONFIG GET dir --> "/var/lib/redis" 和 CONFIG GET dbfilename --> "redis.rdb". 但
我是一名优秀的程序员,十分优秀!