【发布时间】:2018-09-04 11:47:12
【问题描述】:
嗨,这是我的 hmtl 和 JS 到目前为止,我希望它也能检测 iframe 窗口中的鼠标移动、滚动和箭头,因为大多数网站都在 iframe 中,所以我在其他地方寻找过所有似乎都过分的地方检测运动很复杂。
任何帮助将不胜感激 谢谢你
<script type="text/javascript">
// Set timeout variables.
var timoutWarning = 1000; // Display warning in 1Mins.
var timoutNow = 2000; // Timeout in 2 mins.
var warningTimer;
var timeoutTimer;
// Start timers.
function StartTimers() {
warningTimer = setTimeout("IdleWarning()", timoutWarning);
timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
}
// Reset timers.
function ResetTimers() {
clearTimeout(warningTimer);
clearTimeout(timeoutTimer);
StartTimers();
$("#timeout").dialog('close');
}
// Show idle timeout warning dialog.
function IdleWarning() {
var answer = confirm("Session About To Timeout\n\n You will be automatically logged out.\n Confirm to remain logged in.")
if (answer){
ResetTimers();
}
else{
IdleTimeout();
}
}
// Logout the user and auto reload or use this window.open('http://www.YourPageAdress.com', '_self'); to auto load a page.
function IdleTimeout() {
window.open(self.location,'_top');
}
</script>
<body onload="StartTimers();" onmousemove="ResetTimers();" onKeyPress="ResetTimers();"
【问题讨论】:
-
每个框架都有自己的窗口,事件发生在该窗口内,不会冒泡到框架的父级。因此,您还需要能够监听这些框架内的移动并与首页协调
标签: javascript html iframe timeout