javascript setTimeout does not work

Discussion in 'ASP .Net' started by =?Utf-8?B?RQ==?=, May 2, 2006.

  1. I am having trouble with setTimeout working on a second call to the
    setTimeout function from a second page which is an html page.

    Here is the scenario.

    I have a web page and onload it calls a javascript function which calls
    setTimeout and will process a second javascript function "Warn" just before
    the session expires. The Warn function displays an html page with a
    button. A second timer is started to cause the html page to close after a
    short period of time. If the button is pressed on the html page then a
    non-cached asp.net page is called and the first timer is started again and
    then the html page is closed. This way the first timer fails to work.

    If I am calling from the html page the setTimeout function just before I
    close the html page, will that cause the setTimeout function to not work?
    (This is what appears to be happening. Is there any work around.)

    Or can someone tell me how I can somehow get the first asp.net page to start
    the timer again - call setTimeout again from the html page that was started
    through the setTimeout function?

    Any insight would be appreciated!!!!

    --
    Ed Reyes
    =?Utf-8?B?RQ==?=, May 2, 2006
    #1
    1. Advertising

  2. Let me see if I can be more descriptive in the issue.



    I am having trouble with setTimeout working on a second call to the
    setTimeout function from a second page which is an html page.

    Here is the scenario.

    I have an asp.net web page and through the onload event it calls a
    javascript function which calls
    setTimeout which will be used to indicate a session is about to expire.

    The Session timer warning of session expiration will start a second
    javascript function -- "Warn()".

    The Warn function displays an html page -- “delayed-popup-window.html’ --
    using window.open and start another timer which upon countdown will cause the
    html page to close after a short period of time. The
    “delayed-popup-window.html’ page has a button and when pressed it indicates
    that session should be active and will close the “delayed-popup-window.html’
    page but attempts to start the first timer again to once again warn of a
    session timeout. This is when the first timer fails to work.

    From the “delayed-popup-window.html’ page – when I close the close the html
    page just after I call the setTimeout, the setTimeout function seems to not
    work?

    (This is what appears to be happening. Is there any work around?)
    Or can someone tell me how I can somehow get the first asp.net page to start
    the timer again. In other words, have the first asp.net page call the
    setTimeout function again but somehow this event or capability has to be
    instigated from the “delayed-popup-window.html’ page that was started through
    the setTimeout function?

    I have considered using setInterval instead of setTimeout. But if I do this
    then the html page must be able to access the return value of the setInterval
    call so that the html can call clearInterval. So if I do this then I need to
    pass to the html page the TimerID. How can I do this?

    Any insight would be appreciated!!!!

    ############################################
    This is the warn.js file


    var timerID;





    function Warn()

    {

    var delayed;



    windowprops = "left=350,top=350,width=267,height=103";

    delayed = window.open( "/bms/Expiration/delayed-popup-window.html",
    "preview", windowprops );

    setTimeout("delayed.close();", 30000 );

    }



    function doWarnPrep()

    {

    timerID = setTimeout ("Warn();", 1 * 60000 );

    }



    ###################################
    This is typical of the first asp.net page

    <%@ Register TagPrefix="HDR" TagName="UserHeader" Src=
    "/bms/EdgarHeader.ascx" %>
    <%@ Register TagPrefix="FTR" TagName="UserFooter" Src=
    "/bms/EdgarFooter.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <HTML>
    <HEAD>
    <title>Default</title>
    <script language="javascript" src="JScripts/Default.js"
    type="text/javascript"></script>
    <script language="javascript" src="/bms/scripts/date.js"
    type="text/javascript"></script>
    <meta content="Microsoft Visual Studio 7.0"
    name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta
    content="http://schemas.microsoft.com/intellisense/ie5"
    name="vs_targetSchema">
    <LINK href="/bms/css/main.css" type="text/css"
    rel="stylesheet">
    <LINK href="/bms/css/secondary.css" type="text/css"
    rel="stylesheet">
    <LINK href="/bms/css/forms.css" type="text/css"
    rel="stylesheet">
    <script language="JavaScript"
    src="/bms/javascript/scripts.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript"
    src="/bms/Expiration/javascripts/Warn.js"></script>
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    window.onload=startList;
    //--><!]]>
    </script>
    <script language="javascript"
    src="../scripts/edgar.js"></script>
    </HEAD>
    <body MS_POSITIONING="GridLayout" onload="javascript:doWarnPrep()">

    And so on…
    ##########################
    This is the delayed-popup-window.html


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio
    ..NET 7.1">
    <meta name="ProgId" content="VisualStudio.HTML">
    <meta name="Originator" content="Microsoft Visual Studio
    ..NET 7.1">
    <script language="javascript" type="text/javascript"
    src="/bms/Expiration/javascripts/Warn.js"></script>
    <script language="javascript">
    function RefreshButton()
    {
    timerID = setTimeout ("Warn();", 1 *
    60000 ); //ISSUE IS HERE********************

    window.close();
    }

    </script>
    </head>
    <body>
    <form>
    <table bgcolor="#0" BORDER="0"
    CELLSPACING="1" CELLPADDING="5" ID="Table1">
    <tr>
    <td width="192"
    bgcolor="#99cc33" valign="top" rowspan="2" class="bodytext">
    <br><STRONG>Due
    to Inactivity. Session will expire in 2 minutes</STRONG><br>
    </td>
    </tr>
    <tr>
    <td bgColor="#99cc33">
    <input
    type="button" value="Press to Stay Connected"

    onclick="javascript:RefreshButton();" runat="server">
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>



    --
    Ed Reyes





    --
    Ed Reyes



    "E" wrote:

    > I am having trouble with setTimeout working on a second call to the
    > setTimeout function from a second page which is an html page.
    >
    > Here is the scenario.
    >
    > I have a web page and onload it calls a javascript function which calls
    > setTimeout and will process a second javascript function "Warn" just before
    > the session expires. The Warn function displays an html page with a
    > button. A second timer is started to cause the html page to close after a
    > short period of time. If the button is pressed on the html page then a
    > non-cached asp.net page is called and the first timer is started again and
    > then the html page is closed. This way the first timer fails to work.
    >
    > If I am calling from the html page the setTimeout function just before I
    > close the html page, will that cause the setTimeout function to not work?
    > (This is what appears to be happening. Is there any work around.)
    >
    > Or can someone tell me how I can somehow get the first asp.net page to start
    > the timer again - call setTimeout again from the html page that was started
    > through the setTimeout function?
    >
    > Any insight would be appreciated!!!!
    >
    > --
    > Ed Reyes
    >
    =?Utf-8?B?RQ==?=, May 2, 2006
    #2
    1. Advertising

  3. javascript objects only have a lfetime of the page. if your page postsback,
    or navigates to another page, then all objects and timers are destroyed. as
    sessions timeout based on last activity, you should restart the timer on
    every page request. also you need to set the pages as not cached so that
    they always go to the server to reset the timer on the server.

    the only workaround to this is to host your pages in a frrameset, and have
    the parent frame run the timer.

    -- bruce (sqlwork.com)




    "E" <> wrote in message
    news:...
    >I am having trouble with setTimeout working on a second call to the
    > setTimeout function from a second page which is an html page.
    >
    > Here is the scenario.
    >
    > I have a web page and onload it calls a javascript function which calls
    > setTimeout and will process a second javascript function "Warn" just
    > before
    > the session expires. The Warn function displays an html page with a
    > button. A second timer is started to cause the html page to close after a
    > short period of time. If the button is pressed on the html page then a
    > non-cached asp.net page is called and the first timer is started again and
    > then the html page is closed. This way the first timer fails to work.
    >
    > If I am calling from the html page the setTimeout function just before I
    > close the html page, will that cause the setTimeout function to not work?
    > (This is what appears to be happening. Is there any work around.)
    >
    > Or can someone tell me how I can somehow get the first asp.net page to
    > start
    > the timer again - call setTimeout again from the html page that was
    > started
    > through the setTimeout function?
    >
    > Any insight would be appreciated!!!!
    >
    > --
    > Ed Reyes
    >
    bruce barker \(sqlwork.com\), May 2, 2006
    #3
  4. hi bruce,

    Your explanation makes sense and verifies my suspicions. I am still trying
    to find another solution and thought about old techniques as SendMessage and
    PostMessage to different forms in MFC. Then I thought about delegates in C#

    Do you think if I create a delegate on the first asp.net page that would
    essential just restart the timer, and then use that delegate from other pages
    including html pages? As you can tell I have not used delegates yet. Would
    they apply here?


    --
    Ed Reyes



    "bruce barker (sqlwork.com)" wrote:

    > javascript objects only have a lfetime of the page. if your page postsback,
    > or navigates to another page, then all objects and timers are destroyed. as
    > sessions timeout based on last activity, you should restart the timer on
    > every page request. also you need to set the pages as not cached so that
    > they always go to the server to reset the timer on the server.
    >
    > the only workaround to this is to host your pages in a frrameset, and have
    > the parent frame run the timer.
    >
    > -- bruce (sqlwork.com)
    >
    >
    >
    >
    > "E" <> wrote in message
    > news:...
    > >I am having trouble with setTimeout working on a second call to the
    > > setTimeout function from a second page which is an html page.
    > >
    > > Here is the scenario.
    > >
    > > I have a web page and onload it calls a javascript function which calls
    > > setTimeout and will process a second javascript function "Warn" just
    > > before
    > > the session expires. The Warn function displays an html page with a
    > > button. A second timer is started to cause the html page to close after a
    > > short period of time. If the button is pressed on the html page then a
    > > non-cached asp.net page is called and the first timer is started again and
    > > then the html page is closed. This way the first timer fails to work.
    > >
    > > If I am calling from the html page the setTimeout function just before I
    > > close the html page, will that cause the setTimeout function to not work?
    > > (This is what appears to be happening. Is there any work around.)
    > >
    > > Or can someone tell me how I can somehow get the first asp.net page to
    > > start
    > > the timer again - call setTimeout again from the html page that was
    > > started
    > > through the setTimeout function?
    > >
    > > Any insight would be appreciated!!!!
    > >
    > > --
    > > Ed Reyes
    > >

    >
    >
    >
    =?Utf-8?B?RQ==?=, May 2, 2006
    #4
  5. No, the solution is not in server code, as it's the client code that is
    the problem.

    Put a function on the page that restarts the timer. From the popup page
    you just call the function in the parent page, that way the setTimeout
    call will use the window object of parent page, not the popup.

    E wrote:
    > hi bruce,
    >
    > Your explanation makes sense and verifies my suspicions. I am still trying
    > to find another solution and thought about old techniques as SendMessage and
    > PostMessage to different forms in MFC. Then I thought about delegates in C#
    >
    > Do you think if I create a delegate on the first asp.net page that would
    > essential just restart the timer, and then use that delegate from other pages
    > including html pages? As you can tell I have not used delegates yet. Would
    > they apply here?
    >
    >
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=, May 2, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert S
    Replies:
    2
    Views:
    120
    Robert S
    Jul 23, 2006
  2. danep
    Replies:
    1
    Views:
    166
    danep
    Jul 23, 2007
  3. Terry

    Almost got my setTimeout to work

    Terry, Sep 26, 2007, in forum: Javascript
    Replies:
    11
    Views:
    162
    Terry
    Sep 27, 2007
  4. Replies:
    4
    Views:
    225
  5. Aaron Fude

    setTimeout doesn't work

    Aaron Fude, Apr 6, 2008, in forum: Javascript
    Replies:
    3
    Views:
    175
    Lasse Reichstein Nielsen
    Apr 6, 2008
Loading...

Share This Page