Solved

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

Posted on 2011-09-30
6
228 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now