Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setTimeout in Javascript

Status
Not open for further replies.

lilyclar

Programmer
Nov 7, 2003
8
0
0
CA
Hi:

I have alreay a web application using Javascript.

The main.html page (below) inculdes two frames:
The upper frame is the top_frame.html which is for the navigation bar;
The lower frame is welcome.html responsible for the detailed dispaly of presenting data,inputting data, etc.
The welcome.html will be redireted to several other pages depending on the user's request,like one.html, two.html, three.html, etc.

Now, I want to add an auto logout to the system. After a webpage is displayed for 20 minutes,the sytem will log out automatically. Although each page presented to the user is composed of two parts, top_frame.html and welcome.html(or one.html, two.html, etc), the actual timeout depends on the lower part only,that is, welcome.html, one.html, two.html, etc. So I have to insert the code window.setTimeout("logout()",1200000) to every file which will appear in the lower frame. But I have almost 50 such files, it is very time consuming.

Is there an easy way to solve this?

Thanks in advance.

Lily

------------------------------------------------------------
Code for main.html


<HTML>

<HEAD>
<TITLE>A Testing Database</TITLE>
<SERVER> db_check_connection(); </SERVER>
</HEAD>

<FRAMESET rows=&quot;70,*&quot; BORDER=0>
<FRAME name=&quot;header&quot;
src=&quot;top_frame.html&quot; NORESIZE SCROLLING=&quot;no&quot; FRAMEBORDER=&quot;no&quot; >
<FRAME name=&quot;display&quot;
src=&quot;welcome.html&quot; >
</FRAMESET>

</HTML>

------------------------------------------------------------
 
<script language='Javascript'>
window.setTimeout(&quot;somefunction()&quot;,milliseconds);
</script>

somefunction() is a javascript function that you want to execute after the milleseconds expire

-kaht

banghead.gif
 
If you have some sort of server-side control (I see a DB call), why not control timeouts & sessions from there?

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
I would like to time out the user on the server side. But how?

Lily
 
if you use asp for your SSL try this:

Server.ScriptTimeout=360; // 6 minutes to timeout

-kaht

banghead.gif
 
Hi,

I am not using SSL. Can I use <%session.timeout=10 %> to set the session to time out after 10 minutes inactivity. But how can I redirect to the logout.html after the timeout?

Thanks.

Lily
 
SSL = Server Side Language

if you can post this in your page:

<%session.timeout=10 %>

then you are using a server side language. If ASP is your server side language, then you do this:

<%Server.ScriptTimeout=600;%>

to set your timeout value for 10 mins. (The number passed is in seconds)

-kaht

banghead.gif
 
er,
am i worng? but isnt timeout the time allowed for executing a page? i dont think it has anything to do with sessions or that type of functions...

Known is handfull, Unknown is worldfull
 
Vbkris is right, I think I misunderstood your question lilyclar. The code I posted would have allowed your page 10 mins to load, then timed out. This helps prevent your window from hanging when you have a loop in a database call or something. But, any way you look at it, you're gonna have to modify your 50 something files to add the timeout code, and window.timeout does exactly what you want it to, so why not just use it?

-kaht

banghead.gif
 
I could make use of window.setTimeout, and let it do some logout() function when time is up. But this will cause problems if I insert the window.setTimeout statement into my 50 files.For example, when one.html pops up two.html, two.html pops up three.html, then one.html will timeout first and get me logged out at the time that I am still active at three.html. Can I keep a general variable somewhere, so that each time when a new page is open, the variable will be set back to 20 mins again? I would like to make use of client object in LiveWire(because I am using Netscape Enterprise Sever) not session in ASP. Do you have any code to implement this?

It would be very appriciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top