Solved

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

Posted on 2011-09-30
6
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 37
displaying 3 dropdownlist  horizontally 3 32
What cart is this? 2 34
Validating number not work with decimal 4 24
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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