By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

javascript setTimeout does not work

P: n/a
E
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

May 2 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
E
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

May 2 '06 #2

P: n/a
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" <E@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
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

May 2 '06 #3

P: n/a
E
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" <E@discussions.microsoft.com> wrote in message
news:0A**********************************@microsof t.com...
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


May 2 '06 #4

P: n/a
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?

May 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.