Solved

Problem with stopping time when opened tab is changed or not..........

Posted on 2011-09-30
6
229 Views
Last Modified: 2012-05-12
I am using setTimeout function to run time in my javascript application ....is there any method that i can stop application when the tab where timer is running changes..........?????
0
Comment
Question by:savsoft
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36890819
if you want don't want the user to trigger any event on the screen when the timer is ticking, then you need to overlay a transparent div on top of your screen.
0
 

Author Comment

by:savsoft
ID: 36890825
i am using setTimeout fintion to run timer in one page i want that if any one open or minimize that page/tab then time will pause.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36890847
window.onblur = function() {
   //stop the timer
};

window.onfocus = function() {
   //start the timer from the last value
};
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:savsoft
ID: 36890872
But I also want tomaintain the time where tab is changed and time coming back too
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36890907
you can save the timer value at the blur event and start the timer again from saved value on focus, right?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36891020
update your setTimeout :

<script language="javascript" type="text/javascript">

var pause = false; // default value

setTimeout(function() {
         if( !pause ) {
             // your current code here
             // I suppose you've an other setTimeout here too
         }
}, 1000); // 1000 is your current delay

to stop it, just set pause to true :

pause = true;
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question