Hello everyone!!!!!!!

I am using the following timescript code in master pages for 2 projects in same solution. I need to embed this JS in a common library.

My question is: This timeout script redirects to "Timeout.aspx" page after 15 mins of inactivity. Now this path location is different for both the projects. So if I embed this in a common project folder and give a reference to this JS from the reqd 2 project folders. Then how can I change the redirect path location?

Would appreciate if somebody can help me with the code.

// JScript File

function ParentTimeOut()
{
var timeout  = 60000 * 1; // 15 minutes
var pageStarted  = new Date(); // initial time
var timeOutVal = Converter.ToString(timeout));
var sinceLastCheck = new Date() ;
var ele document.getElementById('ValidationSummary1.ClientID');

     if (Request.IsAuthenticated)
        { // if user is logged in, then set timeout script
            timeout ();
            function timeout ()
           {

              if (window.document.location.href.indexOf('timeout') == -1)
               {
                   if ((sinceLastCheck - pageStarted) > timeOutVal)
                       {
                         document.location.href= 'Timeout.aspx';
                       }

                }
                sinceLastCheck = new Date();

                var t=setTimeout('timeout()',10000);
             }

          }
                       // the progress display script here
                      var imageInfo=['/images/loader.gif', 16, 16]; // image src, width, height");                                

                       stopAni();
                       }

function startAni(sender, args, offset)
                       {///////////************some code in here**********//////////////}

function stopAni()
                      {///////////************some code in here**********//////////////}

Recommended Answers

All 2 Replies

I'm guessing you want a different redirect based on some portion of the url. I could be wrong. What I would do is let JavaScript get the URL, trim it down to just the domain name using substring, and then compare the domain name to one of the possible values. If equal redirect to one point, else redirect to another:

if ((sinceLastCheck - pageStarted) > timeOutVal)
{
    var theURL = document.location.href;//get the url
    theURL=theURL.replace("http://www.","");//remove 'http://' from beginning
    theURL=theURL.substring(0, 13);//Remove everything from string except for the domain name. You'll have to adjust this to the exact length of the domain name length.
    if(theURL=="w3schools.com")
    {
      document.location.href="Timeout.aspx";
    }
    else
    {
    document.location.href="Another_Timeout.aspx";
    }
}

Thanks for your reply Lee!

You got that right, but URL can be http (production server) https(development server)
This code will be different for both the cases i guess and that is not feasible.

I was trying to use following code in the page (this page is in different project folder) in which the last declaration and value will take presidence, and the code will dynamically create the URL to the page, regardless if it is http or https.

string timeoutPage = "Timeout1.aspx";
string timeoutLocation = this.Request.Url.GetLeftPart(UriPartial.Authority) + this.Request.ApplicationPath + timeoutPage;

string timeoutLocationScript1 = Page.ClientScript.GetWebResourceUrl(this.GetType(), "SmartyPig.Common.Web.Timeout.js"); // referencing embedded Timeout.js file 

Page.ClientScript.RegisterStartupScript(typeof(Page), "SmartyPig.Common.Web.Timeout.js", timeoutLocationScript1);

But now as I am trying to change the value of var g_timeoutLocation (defined in embedded timescript.js) so need to change the string timeoutLocationScript1 as following:

string timeoutLocationScript1 = Page.ClientScript.GetWebResourceUrl(this.GetType(), (StringHelper.FormatString("\n<script type='text/javascript'>\nvar g_timeoutLocation = '{0}';\n</script>\n", timeoutLocation)));

Now, I am very bad at JS coding and dont know how to correctly write this code line so as to refer the embedded script variable and change it value.

Would appreciate any help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.