如何在JS中传递参数 [英] how to pass the parameter in JS

查看:71
本文介绍了如何在JS中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个javascript函数,因为我有一个值,需要用该值调用相同的javascript.

我的JS:

Hi,

I have a javascript function, in that i have a value, need to call the same javascript with the value.

My JS:

function DisplaySessionTimeout(sessionTimeout) {
           sessionTimeout = sessionTimeout - 1;
           alert(sessionTimeout);
            if (sessionTimeout >= 0)
                window.setTimeout('DisplaySessionTimeout(sessionTimeout)', 60000);
            else {
                
                alert("Your current Session is over.");
                window.close();
            } 
        }



在window.setTimeout中,我需要使用sessionTimeout作为输入参数调用相同的javascript.当我像上面那样传递参数时,它将值显示为"Nan".

问候,
Basha.



in window.setTimeout i need to call the same javascript with sessionTimeout as the input parameter. When i am passing the parameter like above it shows the value as "Nan".

Regards,
Basha.

推荐答案

像这样

like this way

<script language="javascript" type="text/javascript">
       var sessionTimeoutWarning = "<%= System.Configuration.ConfigurationSettings.AppSettings["SessionWarning"].ToString()%>";
       var sessionTimeout = "<%= Session.Timeout %>";
       var timeOnPageLoad = new Date();
       var sessionWarningTimer = null;
       var redirectToWelcomePageTimer = null;
       //For warning
       var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
       //To redirect to the welcome page
       var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);

       //Session Warning
       function SessionWarning() {
           //minutes left for expiry
           var minutesForExpiry =  (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
           var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";

           //Confirm the user if he wants to extend the session
           answer = confirm(message);

           //if yes, extend the session.
           if(answer)
           {

               //Clear the RedirectToWelcomePage method
               if (redirectToWelcomePageTimer != null) {
                   clearTimeout(redirectToWelcomePageTimer);
               }
               timeOnPageLoad =  new Date();
               sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
               //To redirect to the welcome page
               redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()',parseInt(sessionTimeout) * 60 * 1000);
           }

           //*************************
           //Even after clicking ok(extending session) or cancel button, if the session time is over. Then exit the session.
           var currentTime = new Date();
           //time for expiry
           var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));

           //Current time is greater than the expiry time
           if(Date.parse(currentTime) > timeForExpiry)
           {
               alert("Session expired. You will be redirected to welcome page");
               window.location = "Default.aspx";
           }
           //**************************
       }

       //Session timeout
       function RedirectToWelcomePage(){
           alert("Session expired. You will be redirected to welcome page");
           window.location = "Default.aspx";
       }
   </script>


我将修改您的JS函数,它看起来像:

Hi, I will just modify your JS function and it looks like:

function DisplaySessionTimeout(sessionTimeout) {
           sessionTimeout = parseInt(sessionTimeout) - 1;
           alert(sessionTimeout);
            if (sessionTimeout >= 0)
   window.setTimeout('DisplaySessionTimeout('+sessionTimeout+')', 60000);
            else {

                alert('Your current Session is over.');
                window.close();
            }
        }




希望这会起作用.




Hope this will work.


这篇关于如何在JS中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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