gpt4 book ai didi

javascript - 将 window.SessionTimeout 脚本传递到 js 文件

转载 作者:行者123 更新时间:2023-11-28 08:15:02 25 4
gpt4 key购买 nike

我正在做一个 MVC 应用程序。这是我的 _Layout.cshtml

我需要将其移动到 js 文件

<script type="text/javascript">
window.SessionTimeout = (function() {
var _timeLeft, _popupTimer, _countDownTimer;

var stopTimers = function() {
window.clearTimeout(_popupTimer);
window.clearTimeout(_countDownTimer);
};

var updateCountDown = function() {
var min = Math.floor(_timeLeft / 60);
var sec = _timeLeft % 60;
if(sec < 10)
sec = "0" + sec;

document.getElementById("CountDownHolder").innerHTML = min + ":" + sec;

if(_timeLeft > 0) {
_timeLeft--;
_countDownTimer = window.setTimeout(updateCountDown, 1000);
} else {
document.location = "Home/TimeOutPage";
}
};

var showPopup = function() {
_timeLeft = 60;
updateCountDown();
ClientTimeoutPopup.Show();
};

var schedulePopup = function() {
stopTimers();
_popupTimer = window.setTimeout(showPopup, @PopupShowDelay);
};

var sendKeepAlive = function() {
stopTimers();
ClientTimeoutPopup.Hide();
SessionTimeout.schedulePopup();
};

return {
schedulePopup: schedulePopup,
sendKeepAlive: sendKeepAlive
};

})();

我尝试仅复制脚本标记之间的代码,但它不起作用。我知道问题出在函数签名上

window.SessionTimeout = (function() { ...

但我不知道如何在 js 文件中使用 window.SessionTimeout

@PopupShowDelay 在我看来是这样定义的:

       @functions { 
public int PopupShowDelay
{
get { return 60000 * (Session.Timeout - 1); }
}
}

更新

好的,我发现错误了。问题是变量

@PopupShowDelay

我在 View 中定义了它,并尝试读取.js文件。

所以,我要检查一下: Passing parameters to JavaScript files

谢谢!!

最佳答案

嵌套函数中的 this 上下文可能会出现问题。 You can read more here

关于javascript - 将 window.SessionTimeout 脚本传递到 js 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23704797/

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