所以我发现这个jquery插件http://www.paulirish.com/2009/jquery-idletimer-plugin/ a在经过x秒后自动重定向。我想将其合并到一个角度视图中,但是我无法使用带有jquery函数的ng路径。程序运行但超时,因为jquery不识别“#”路由。如果我把视图的原始链接(main.html),这将我带到页面,但退出应用程序。我也尝试设置iframe,因为我只是想弹出,但我得到一个http错误请求
会话到期警告
你已经有一段时间不活跃了。单击“继续”以扩展您的会话。
您的会话将在120秒后过期。
继续
</div>
</div>
</div>
</div>
<div class="modal fade" id="mdlLoggedOut" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">You have been automatically signed out</h4>
</div>
<div class="modal-body">
<p>Your session has expired.</p>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<script>
(function ($) {
var
session = {
//Logout Settings
inactiveTimeout: 10000, //(ms) The time until we display a warning message
warningTimeout: 10000, //(ms) The time until we log them out
minWarning: 5000, //(ms) If they come back to page (on mobile), The minumum amount, before we just log them out
warningStart: null, //Date time the warning was started
warningTimer: null, //Timer running every second to countdown to logout
logout: function () { //Logout function once warningTimeout has expired
//window.location = settings.autologout.logouturl;
$(location).attr('href', 'main.html')
},
//Keepalive Settings
keepaliveTimer: null,
keepaliveUrl: "",
keepaliveInterval: 5000, //(ms) the interval to call said url
keepAlive: function () {
$.ajax({ url: session.keepaliveUrl });
}
}
;
$(document).on("idle.idleTimer", function (event, elem, obj) {
//Get time when user was last active
var
diff = (+new Date()) - obj.lastActive - obj.timeout,
warning = (+new Date()) - diff
;
//On mobile js is paused, so see if this was triggered while we were sleeping
if (diff >= session.warningTimeout || warning <= session.minWarning) {
window.location.replace("#");
} else {
//Show dialog, and note the time
$('#sessionSecondsRemaining').html(Math.round((session.warningTimeout - diff) / 1000));
$("#timeout").modal("show");
session.warningStart = (+new Date()) - diff;
//Update counter downer every second
session.warningTimer = setInterval(function () {
var remaining = Math.round((session.warningTimeout / 1000) - (((+new Date()) - session.warningStart) / 1000));
if (remaining >= 0) {
$('#sessionSecondsRemaining').html(remaining);
} else {
session.logout();
}
}, 1000)
}
});
// create a timer to keep server session alive, independent of idle timer
session.keepaliveTimer = setInterval(function () {
session.keepAlive();
}, session.keepaliveInterval);
//User clicked ok to extend session
$("#extendSession").click(function () {
clearTimeout(session.warningTimer);
});
//User clicked logout
$("#logoutSession").click(function () {
session.logout();
});
//Set up the timer, if inactive for 10 seconds log them out
$(document).idleTimer(session.inactiveTimeout);
})(jQuery);
</script>
答案 0 :(得分:0)
将jquery与angular混合不是一个好主意。如果您想在一段时间后实现网址重定向,可以通过以下方法实现此目的
var timeoutperiod;
var redirect = function (url){
$window.location.href = url;
};
if (timeoutperiod) {
clearTimeout(timeoutperiod);
}
timeoutperiod = setTimeout(redirect('url'), 5000);
请确保将$ window注入控制器。