I´m doing an MVC app. And this is in my _Layout.cshtml
I need to move it to a a js file
<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
};
})();
I try to copy only the code between the script tag but it doesn't work. I know the problem is with the function signature
window.SessionTimeout = (function() { ...
but i don´t know hot to use window.SessionTimeout in a js file.
The @PopupShowDelay is define in my view like this:
@functions {
public int PopupShowDelay
{
get { return 60000 * (Session.Timeout - 1); }
}
}
UPDATE
Ok, i found the error. The problem is the variable
@PopupShowDelay
I defined that at the view and was trying to read the .js file.
So, i'm going tho check this: Passing parameters to JavaScript files
Thankls!!