JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 12th, 2008, 01:42 AM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 270 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 38 sec
Reputation Power: 10
Alert after time of inactivity then click to logout

I am sure this is simple.
On most bank websites after 10 mins or so of inactivity an alert box pops up saying that you will be logged out.

How do you do that?
I figured you can use settimeout on the onload maybe?

the other thing is what happens when the user clicks the OK button on the alert box? How do you get that to trigger the page to go to the logout page?

Thanks

Reply With Quote
  #2  
Old January 12th, 2008, 02:12 AM
bals28mjk's Avatar
bals28mjk bals28mjk is offline
Person
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2007
Location: Moon
Posts: 1,158 bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 6 h 1 m 45 sec
Reputation Power: 549
Precisely. Though, your forgetting how to trigger the idle state; you will have to clear it (clearTimeout) and set it (setTimeout) every time the user moves the mouse in the document (document.onmousemove).

Quote:
How do you get that to trigger the page to go to the logout page?
location.href
Comments on this post
tbankar agrees!
__________________
Give Opera some love. Use it and you'll see why.

Oh, those monkeys.::What's wrong with the world today?::The lion king in 5 seconds.

My body is so sexy.

Reply With Quote
  #3  
Old January 12th, 2008, 04:45 AM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,832 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 20 h 44 m 58 sec
Reputation Power: 4192
You should probably listen for document.onkeyup events too.
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
  #4  
Old January 12th, 2008, 12:11 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 270 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 38 sec
Reputation Power: 10
Quote:
Originally Posted by bals28mjk
Precisely. Though, your forgetting how to trigger the idle state; you will have to clear it (clearTimeout) and set it (setTimeout) every time the user moves the mouse in the document (document.onmousemove).

location.href

I still am missing something. when I do the location.href it doesn't wait for the alert box to show up. it just sends me there immediately. I am quite rusty in working with js.

Code:
<script type="text/javascript">
setTimeout("alert('5 seconds!')",5000)
location.href='http://yahoo.com' 
</script>

Reply With Quote
  #5  
Old January 12th, 2008, 04:05 PM
bals28mjk's Avatar
bals28mjk bals28mjk is offline
Person
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2007
Location: Moon
Posts: 1,158 bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 6 h 1 m 45 sec
Reputation Power: 549
Hi, you need to put the alert message and page redirect into a function and place a function reference for that function in the first parameter of setTimeout.

Reply With Quote
  #6  
Old January 12th, 2008, 07:27 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,179 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 15 h 42 m 16 sec
Reputation Power: 57
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
If all you would need is the alert and redirect, then this should be fine... however I can't remember if it is with or without the quotes.
Code:
var t= window.setTimeout("function(){ alert('5 seconds'); window.location.href='www.devshed.com/'; }", 5000);


if you need more than what's there above... something to this effect is what I'd do...
Code:
function isInactive(){
  var msg= "Notice of Inactivity and allow confirm of redirection...";
  var temp= (window.confirm(msg)) ? 'www.devshed.com/' : null;
  if (temp) window.location.href= temp;
}
var t= window.setTimeout("isInactive()", 5000);
__________________
Download [ Fx | Op ] Validate [ Markup | Css ]

Reply With Quote
  #7  
Old January 12th, 2008, 10:48 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 270 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 38 sec
Reputation Power: 10
getting there, but more questions

Thank for all your help so far.

I have this so far.
Code:
<script type="text/javascript">
function logout()
{
alert('You have been logged out.')
location.href='logout.php' 
}

function resetlogout()
{
clearTimeout(t);
}

var t= setTimeout("logout()",5000)
</script>

and the resetlogout() function is called on a onKeyUp="resetlogout()" on one of the fields that needs to filled in to continue.

I know it will reset the setTimeout on the page reload which happens after a transaction, but how can I get it to reset the Timeout countdown after the KeyUp?

Also I have it go to the logout page but if you click back in the browser it just takes you right back to the page with all the info. It shouldn't do that should it? The user should have been logged out.
I am sure it may have something to do with my logout page. Maybe I am not destroying the session properly.

Reply With Quote
  #8  
Old January 13th, 2008, 01:48 AM
bals28mjk's Avatar
bals28mjk bals28mjk is offline
Person
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2007
Location: Moon
Posts: 1,158 bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 6 h 1 m 45 sec
Reputation Power: 549
Quote:
Originally Posted by jsKid
If all you would need is the alert and redirect, then this should be fine... however I can't remember if it is with or without the quotes.
function references are without, (the first one with the anonymous function shouldn't have quotes).
Quote:
Originally Posted by jsKid
if you need more than what's there above... something to this effect is what I'd do...
So you are telling the user to confirm that he's not there? Lol jsKid, think about that.


Quote:
Originally Posted by Kravvitz
You should probably listen for document.onkeyup events too.
I forgot to mention, Kravvitz, that I like your idea.


Quote:
Originally Posted by dandcp
and the resetlogout() function is called on a onKeyUp="resetlogout()" on one of the fields that needs to filled in to continue.
Why just one? I'd do it for the whole document.
JavaScript Code:
Original - JavaScript Code
  1. var t;
  2. document.onmousemove=to
  3. document.onkeypress=to
  4. function logout()
  5. {
  6. alert('You have been logged out.')
  7. location.href='http://www.google.com'
  8. }
  9. function to(){
  10. clearTimeout(t);
  11. t=setTimeout(logout,5000)//logs out in 5 seconds
  12. }
Also, I just noticed that onmousemove is always firing in ie, even when the mouse is stationary inside the document (but not outside,) your probably going to have to write a workaround for this probably checking if the mouse coordinates have changed.

Reply With Quote
  #9  
Old January 13th, 2008, 12:06 PM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,179 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 15 h 42 m 16 sec
Reputation Power: 57
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
haha good point... it was more of an example than anything really
but definitely funny in retrospect.

I'm for including krav idea as well.

Reply With Quote
  #10  
Old January 14th, 2008, 06:44 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 270 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 38 sec
Reputation Power: 10
Thanks

Thanks everyone. This is what I ended up with and seems to be ok for what I need.

Code:
<script type="text/javascript">
var t;
window.onload=resetTimer;
document.onkeypress=resetTimer;

function logout()
{
	alert("You are now logged out.")
	location.href='logout.php' 
}
function resetTimer()
{
	clearTimeout(t);
	t=setTimeout(logout,1800000) //logs out in 30 minutes
}
</script>


Again, I know this is probably not a js thing but after it gets sent to logout.php the user could easily just hit back button and see the previous page. What am I missing? I noticed on my bank website you can't seem to go back. How is that done?

Reply With Quote
  #11  
Old January 14th, 2008, 07:21 PM
bals28mjk's Avatar
bals28mjk bals28mjk is offline
Person
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2007
Location: Moon
Posts: 1,158 bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level)bals28mjk User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 6 h 1 m 45 sec
Reputation Power: 549
Quote:
Again, I know this is probably not a js thing but after it gets sent to logout.php the user could easily just hit back button and see the previous page. What am I missing? I noticed on my bank website you can't seem to go back. How is that done?
You're right dandcp, this is no longer a JavaScript thing.

I'd probably start a new thread in the php forum if you are having problems with the session.

(Also, you may suggest a moderator to move this thread for you.)

@jsKid Lol.

Reply With Quote
  #12  
Old January 14th, 2008, 09:20 PM
dandcp's Avatar
dandcp dandcp is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: CA, USA
Posts: 270 dandcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 38 sec
Reputation Power: 10
no problem.

Thanks everyone for you help on the js section.

I am heading back to the php section.

see you later!

Reply With Quote
  #13  
Old December 22nd, 2012, 04:28 PM
destroyer100 destroyer100 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 destroyer100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 24 sec
Reputation Power: 0
Yea you need a script that ends the session like my examples

You need an end session script to go witht that (its pure php) Check out my example on my site theclanz.netau.net )
Quote:
Originally Posted by dandcp
Thanks everyone. This is what I ended up with and seems to be ok for what I need.

Code:
<script type="text/javascript">
var t;
window.onload=resetTimer;
document.onkeypress=resetTimer;

function logout()
{
	alert("You are now logged out.")
	location.href='logout.php' 
}
function resetTimer()
{
	clearTimeout(t);
	t=setTimeout(logout,1800000) //logs out in 30 minutes
}
</script>


Again, I know this is probably not a js thing but after it gets sent to logout.php the user could easily just hit back button and see the previous page. What am I missing? I noticed on my bank website you can't seem to go back. How is that done?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Alert after time of inactivity then click to logout

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap