The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
Alert after time of inactivity then click to logout
Discuss Alert after time of inactivity then click to logout in the JavaScript Development forum on Dev Shed. Alert after time of inactivity then click to logout JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 12th, 2008, 01:42 AM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Location: CA, USA
Posts: 270
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
|

January 12th, 2008, 02:12 AM
|
 |
Person
|
|
Join Date: Jan 2007
Location: Moon
|
|
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
|

January 12th, 2008, 04:45 AM
|
 |
CSS & JS/DOM Adept
|
|
Join Date: Jul 2004
Location: USA
|
|
|
You should probably listen for document.onkeyup events too.
|

January 12th, 2008, 12:11 PM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Location: CA, USA
Posts: 270
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>
|

January 12th, 2008, 04:05 PM
|
 |
Person
|
|
Join Date: Jan 2007
Location: Moon
|
|
|
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.
|

January 12th, 2008, 07:27 PM
|
 |
Application is what Divides Us
|
|
Join Date: Dec 2002
Location: Titusville, FL
|
|
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 ]
|

January 12th, 2008, 10:48 PM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Location: CA, USA
Posts: 270
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.
|

January 13th, 2008, 01:48 AM
|
 |
Person
|
|
Join Date: Jan 2007
Location: Moon
|
|
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 |
|
|
|
var t; document.onmousemove=to document.onkeypress=to function logout() { alert('You have been logged out.') location.href='http://www.google.com' } function to(){ clearTimeout(t); t=setTimeout(logout,5000)//logs out in 5 seconds }
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.
|

January 13th, 2008, 12:06 PM
|
 |
Application is what Divides Us
|
|
Join Date: Dec 2002
Location: Titusville, FL
|
|
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.
|

January 14th, 2008, 06:44 PM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Location: CA, USA
Posts: 270
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?
|

January 14th, 2008, 07:21 PM
|
 |
Person
|
|
Join Date: Jan 2007
Location: Moon
|
|
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.
|

January 14th, 2008, 09:20 PM
|
 |
Contributing User
|
|
Join Date: Jan 2004
Location: CA, USA
Posts: 270
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!
|

December 22nd, 2012, 04:28 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
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? |
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|