gpt4 book ai didi

javascript - 重定向页面上的超时请求无法路由到另一个 Angular View

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:49 30 4
gpt4 key购买 nike

所以我找到了这个 jquery 插件 http://www.paulirish.com/2009/jquery-idletimer-plugin/ a 在经过 x 秒后发生自动重定向。我想将其合并到 Angular View 之一中,但是我无法将 ng 路由与 jquery 函数一起使用。程序运行但超时,因为 jquery 无法识别“#”路由。如果我放置 View 的原始链接 (main.html),这会将我带到页面,但会退出应用程序。我还尝试设置一个 iframe,因为我只想要弹出窗口,但我收到了一个 http 错误请求

session 过期警告

您已经有一段时间没有事件了。单击“继续”以延长您的 session 。

您的 session 将在 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>

最佳答案

混合 jquery 和 angular 不是一个好主意。如果您想在特定时间段后实现 url 重定向,您可以使用以下方法实现此目的

var timeoutperiod;
var redirect = function (url){
$window.location.href = url;
};

if (timeoutperiod) {
clearTimeout(timeoutperiod);
}
timeoutperiod = setTimeout(redirect('url'), 5000);

请确保将 $window 注入(inject)到您的 Controller 中。

关于javascript - 重定向页面上的超时请求无法路由到另一个 Angular View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37934626/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com