解释这个javascript代码行。 [英] explain this javascript line of code.

查看:84
本文介绍了解释这个javascript代码行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



请您解释一下这个javascript代码。



这是代码如果用户在asp.net项目中空闲,则用于在15分钟后重定向到登录页面



Hi experts,

please can you explain me this javascript code.

This is code is used for redirecting to login page after 15 minutes, if the user is idle in asp.net project

<script type="text/javascript">
function InitSessionTimer() {
    /* mReschke 2010-09-29 */
    warn_sec = 59 * 60 * 1000;             //Warning time in milliseconds
    timeout_sec = 60 * 60 * 1000;          //Actual timeout in milliseconds
    show_warning = true;
    epoch = new Date().getTime();
    CheckSessionStatus();
}
InitSessionTimer();
function CheckSessionStatus() {
    /* mReschke 2010-09-29 */

    //Check for session warning
    epoch2 = new Date().getTime();
    if (epoch2 > epoch + warn_sec && epoch2 < epoch + timeout_sec && show_warning) {

        show_warning = false; //Don't show again

        alert_shown = true;

        alert("Your session will timeout in " + Math.round((timeout_sec - warn_sec) / 1000) + " minute, please click a button or navigate to another page to refresh your session before it expires.");

        down = setTimeout("CheckSessionStatus();", 1000);

    } else if (epoch2 > epoch + timeout_sec) {
        alert("Sorry, Your session has timed out.");
        window.location.href = 'Login.aspx';
    } else {
        down = setTimeout("CheckSessionStatus();", 1000);
    }
}
</script>





--------------- ------------------------



请解释我这行代码。



warn_sec = 59 * 60 * 1000;



什么是59,什么是60,什么是1000这里。



请解释谢谢。



如果用户空闲,我想重定向到Login.aspx页面15分钟后。



---------------------------------------

please explain me this line of code.

warn_sec = 59 * 60 * 1000;

what is 59, what is 60 and what is 1000 here.

Please explain thanks.

I want to redirect to Login.aspx page if user is idle after 15 minutes.

推荐答案

它会警告最多59分钟点击按钮,59分钟后它将重定向到登录页面。





1000表示1秒

1000 * 60表示1分钟

1000 * 60 * 59表示59分钟









您需要15分钟的代码。 okyeee,让我解释一下



1000 = 1秒(1000毫秒)

1000 * 60 = 60000毫秒(60秒)

1000 * 60 * 15 = 900000(15分钟)
it will warn upto 59 minutes to click on button and just after 59 minutes it will redirect to login page.


1000 means 1 second
1000 * 60 means 1 minute
1000 * 60 * 59 means 59 minutes




You want code for 15 minutes. okyeee, let me explain

1000 = 1 second (1000 is miliseconds)
1000 * 60 = 60000 miliseconds (60 seconds)
1000 * 60 * 15 = 900000 (15 minutes)


59 * 60 * 1000

59分钟内

60秒隐藏分钟

和1000转换秒数毫秒。





回答为什么有59 ...



59是它转换为小时的最后一个数字(如果它是60那么它将被计为小时)。

所以那里有59.



warn_sec = 59 * 60 * 1000 - 这是警告在第59分钟

timeout_sec = 60 * 60 * 1000 - 当它达到第60分钟即1小时时将超时



通常这种脚本现在用于网络咖啡馆,现在可以在用户即将达到一小时时警告用户。
59 * 60 * 1000
59 is in minutes
60 to covert minutes in seconds
and 1000 to convert the seconds in milliseconds.


To answer why there is 59...

59 is the last number post which it gets converted to Hour (if it would be 60 then it would be counted as hour).
So its 59 there.

warn_sec = 59 * 60 * 1000 - this is to warn on 59th min
timeout_sec = 60 * 60 * 1000 - will time out when it reaches 60th min i.e 1 hour

usually this kind of script is used in cyber cafe now a days to warn the user when it is about to reach an hour.


以下代码可用于重定向用户预定义时间间隔。

代码:

The below code can be used to redirect user after predefined time interval.
Code:
string script = "<SCRIPT Language='JavaScript'> ";
script += "redirection()";
script += "</SCRIPT>";
Page.RegisterClientScriptBlock("ClientScript", script);



Javascript(将其添加到页面顶部):


Javascript (Add it to the head of the page):

<script type="text/javascript">
     function redirection()
     {
        alert('You wil be redirected to Google.com after 10 seconds.');
        setTimeout("top.location.href = 'http://www.google.com'", 10000);
     }
</script>



问候..:)


Regards..:)


这篇关于解释这个javascript代码行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆