Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Hi all,
 
Is there a way to use same javascript timer variable from multiple tab pages?
Can I save it to somewhere like cookie?
 
For more details:
I'm developing a ASP.Net web page that shows countdown timer 1 minute before session was expired. I implemented this by adding javascript timer (setinterval method). Timer was reset on every Client (Ajax) or Server postbacks.
In every timer tick, I write TimeOutValue-1 into cookie file. When the value of cookie less than or equal to 60 (1 minute), I show a new form that contains "Extend" or "Logout" buttons.
Problem is if I open two tab pages, both page run with their own timers and reducing value from cookie together.
So, if I have only one page, value will be reduce like 10, 9, 8, 7, 6, etc...
If I have two pages, it have been reducing 10, 8, 6, 4, etc... Frown | :(
 
My approach my be wrong coz I am very new to Javascript.
Please give some solution or guide me to achieve this goal.
 

Thanks in advanced
Posted 14-Jan-13 22:37pm
tslin89562
Edited 15-Jan-13 20:07pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

1. Why timer stores value in a cookie file? If your page reloads with F5 - than you can get the timer value from server session variables,
 
if your page is not reloaded, you can create some javascript singleton for timer logic to be used by all tabs (for example component may raise the custom event 'out of time', and your page logic will react on it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I stored timer value in cookie file because I want every tabs to show same timer value when one of the tab performs a postback. Let say, user open a tab (tab1) and it's counting down from 120, 119, 118, etc. If he open another tab (tab2), timer value from tab1 was not reflect or reset and continuing to 117, 116, ... while tab2 have counting down from 120, 119, etc...
With saving value in cookie, if tab2 have make any postback, cookie value was changed back to 120. Then, tab1 also have the same value 120. And counting down...
 
Quote:
if your page is not reloaded, you can create some javascript singleton for timer logic to be used by all tabs (for example component may raise the custom event 'out of time', and your page logic will react on it.

I don't know how to do this. Can you explain more details with sample codes?
 
Thanks.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100