SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Event halts timer

    Hi All

    I have a javascript script that counts down 10 minutes and displays it in the top corner. On the 10 minute time limit there is an event that directs the person to a page which logs them off.

    I am trying to create a 1 minute warning pop up alert window which I can get to work but the alert window itself halts the 10 minute countdown execution.

    Is there any ideas of getting the alert to sit outside of the execution of hte countdown. The script looks like this

    Code:
    	// Take user here after session timed out
    	timedouturl = "index.php?doLogout=true";
    	
    	function Minutes(data) {
    	for (var i = 0; i < data.length; i++)
    	if (data.substring(i, i + 1) == ":")
    	break;
    	return (data.substring(0, i));
    	}
    	function Seconds(data) {
    	for (var i = 0; i < data.length; i++)
    	if (data.substring(i, i + 1) == ":")
    	break;
    	return (data.substring(i + 1, data.length));
    	}
    	function Display(min, sec) {
    	var disp;
    	if (min <= 9) disp = " 0";
    	else disp = " ";
    	disp += min + ":";
    	if (sec <= 9) disp += "0" + sec;
    	else disp += sec; 
    	return (disp);
    	}
    	function Down() { 
    	sec--;      
    	if (sec == -1) { sec = 59; min--; }
    	document.timerform.clock.value = Display(min, sec);
    	window.status = "Session will time out in: " + Display(min, sec);
    	if (min == 0 && sec == 0) {
    	alert("Your session has timed out.");
    	window.location.href = timedouturl;
    	}
    	else down = setTimeout("Down()", 1000);
    	}
    	function timeIt() {
    	min = 1 * Minutes(document.timerform.clock.value);
    	sec = 0 + Seconds(document.timerform.clock.value);
    	Down();
    	}
    	//  End -->
    and the trigger is
    Code:
      <body OnLoad="timeIt()">
    Hope you guys can help this is a real head scratcher. Im not an expert but learning.

    Regards

    Keith

  2. #2
    SitePoint Member
    Join Date
    Sep 2010
    Location
    Massachusetts
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using Javascript's alert as a 1 minute timeout warning is bad usability practice. Something that would solve your problem and the usability problem is to, instead of using alert, have the Javascript trigger a fixed-positioned warning element on the side of the user's screen (make sure it doesn't obscure anything).

  3. #3
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply Azuaron!

    Do you mean use javascript to show/ hide is css a message that is built into the page already?

    great idea. Thank you.

    Im sure there is loads on google about this kind of thing

    k


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •