添加事件以防止Inappbrowser内超时
Add event to prevent timeout inside Inappbrowser
我有一个超时功能
var idleTimeOut = 60; // 1 minute
ResetIdleSecondsEvent = function () {
// Reset counter for all listed event
$(document).on("click mousemove keypress touchstart touchend touchcancel touchmove", function () {
_idleSecondsCounter = 0;
})
}
function VerifyTimeOutInterval() {
// Run every seconds to call function and check if current counter is more than
// the preset time
window.setInterval(CheckIdleTime, 1000);
}
function CheckIdleTime() {
// Check timer only predefined timeout value is not 0, null or empty
if (idleTimeOut != "") {
// Increase counter for seconds
_idleSecondsCounter++;
// Check if current counter is more than the preset timeout period
if (_idleSecondsCounter >= idleTimeOut) {
// Notify user that he/she has been automatically logged out
navigator.notification.alert("You have been automatically logged out due " +
"to inactivity. Please login again.", function () { }, "Logged Out", 'OK');
// Navigate to login page
self.navigateLogout();
}
}
}
这在我的应用程序中非常有效,当用户在1分钟内无所事事时,会出现超时消息,并将用户带到登录屏幕。
但是,当用户使用Inappbrowser打开外部链接并有活动时,空闲秒数没有重置,会出现超时消息,并让用户重新登录。那么,如何将相同的代码添加到Inapp浏览器中呢?
据我所知,Inapp浏览器只有事件loadstart、loadstop、loaderror和exit。我尝试了以下代码将事件添加到Inappbrowser中,但没有成功。
var inappBrowserObj = window.open(url, '_blank', 'location=yes');
inappBrowserObj.addEventListener('loadstop', ResetIdleSecondsEvent());
inappBrowserObj.addEventListener('loadstop', VerifyTimeOutInterval());
请告诉我在Inappbrowser中处理超时功能的正确方法是什么。
感谢
在实现事件处理程序时,您的代码似乎是错误的。回调传递不正确,而且不需要为同一事件注册两次处理程序(尽管可以但不是必需的)。您的代码应该是:
inappBrowserObj.addEventListener('loadstop', ResetIdleSecondsEvent);
观察我是如何传递回调的,您的代码将执行该函数,而不是将其作为回调传递。
在ResetIdleSecondsEvent
函数中进行其他函数调用。
我希望这能有所帮助。
相关文章:
- 使用优化器在慢速连接上加载main.js时需要js超时
- 当浏览器控制台未打开时,为什么要求会导致Internet Explorer 9超时
- 超时功能的性能
- 使用不同的超时对数组中的每个项目进行角度动画处理
- 设置第一次执行的超时
- node.js测试事件是否是在不使用超时的情况下使用sinon.js发出的
- 使用javascript和随机暂停/超时快速循环文本
- 如何在jQuery事件处理程序中存储和重用超时
- 当定位模式设置为“0”时,总是达到关于地理定位的超时;仅设备”;
- 为什么页面重新加载会使设置超时无效,以及如何避免
- 立即设置超时
- 在promise中为回调添加超时并拒绝
- 如何设置$.ajax请求的超时,并在超时时间过长时进行重做
- iOS Safari Javascript设置超时问题
- 如何将嵌套设置超时转换为承诺
- XMLHTTPRequest脚本中没有internet连接和超时
- CXP项目中的Javascript超时
- 超时后才能再次单击
- 将变量传递到超时函数的Javascript
- 添加事件以防止Inappbrowser内超时