Javascript 如果发生任何操作,请重定向页面
我正在尝试做一个kiosk应用程序。在这个应用程序中,如果索引页打开时带有post值(index.html?location=5),除了没有post值的索引页,并且在60秒内发生了任何操作,如鼠标悬停或键入,则重定向到没有值的索引页。我正在使用此代码,但是Javascript 如果发生任何操作,请重定向页面,javascript,html,Javascript,Html,我正在尝试做一个kiosk应用程序。在这个应用程序中,如果索引页打开时带有post值(index.html?location=5),除了没有post值的索引页,并且在60秒内发生了任何操作,如鼠标悬停或键入,则重定向到没有值的索引页。我正在使用此代码,但是 function setIdle(cb, seconds) { var timer; var interval = seconds * 1000; function refresh() { clea
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click', refresh);
$(document).on('mouseover', refresh);
var parts = location.pathname.split('/');
if(parts[parts.length - 1] != 'index.html') {
location.href = 'index.html';
}
refresh();
}
setIdle(function() {
location.href = './index.html';
}, 60);
当我运行这段代码时,它正在刷新没有值的索引页。我想不出我该怎么做
我想做什么
如果index.html?location=5,等待60秒,等待任何鼠标或键盘操作,然后返回index.html
如果index.html不选中鼠标或键盘setIdle()
只被调用一次(当页面第一次加载时),这就是条件逻辑所在refresh()
实际上是执行重定向的,但它不在任何类型的if
中,因此无论您在哪个页面上,每次都会调用它
如果页面是index.html
,为什么不完全忽略空闲函数呢
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click', refresh);
$(document).on('mouseover', refresh);
refresh();
}
var parts = location.pathname.split('/');
//If page is not index.html
if(parts[parts.length - 1] != 'index.html') {
//initialize the "idle" functionality
setIdle(function() {
location.href = './index.html';
}, 60);
}
setIdle()
只被调用一次(当页面第一次加载时),这就是条件逻辑所在的位置refresh()
实际上是执行重定向的,但它不在任何类型的if
中,因此无论您在哪个页面上,每次都会调用它
如果页面是index.html
,为什么不完全忽略空闲函数呢
function setIdle(cb, seconds) {
var timer;
var interval = seconds * 1000;
function refresh() {
clearInterval(timer);
timer = setTimeout(cb, interval);
};
$(document).on('keypress, click', refresh);
$(document).on('mouseover', refresh);
refresh();
}
var parts = location.pathname.split('/');
//If page is not index.html
if(parts[parts.length - 1] != 'index.html') {
//initialize the "idle" functionality
setIdle(function() {
location.href = './index.html';
}, 60);
}
我编辑了我的问题。我没有解释。对不起,我编辑了我的问题。我没有解释。很抱歉