Solved

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

Posted on 2011-09-30
6
230 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 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