Solved

Is it possible to have setTimeout not restart when going to different pages on the site?

Posted on 2013-01-10
7
170 Views
Last Modified: 2013-02-11
If I have setTimeout in a script in the header of my site is it possible to have it continue to run as a user goes from page to page without restarting. Is this something I could use cookies to do? Are there any examples I could look at?
0
Comment
Question by:crm624
  • 3
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38765182
0
 
LVL 82

Expert Comment

by:leakim971
ID: 38765210
0
 

Author Comment

by:crm624
ID: 38765225
I'm talking about the setTimeout() Timing event to execute a function after so much time has gone by.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
LVL 82

Expert Comment

by:leakim971
ID: 38765297
yes, the answer to your question is no, you can't
0
 

Author Comment

by:crm624
ID: 38765320
Wouldn't it be possible to time the user and store it in a cookie and then add to the cookie when they go to a different page? Then have the function execute when it gets to a certain time.
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 38766597
Even if you name a setTimeout variable or not, it is supposed to reset on page exit even if you do not use the clearInterval method.
What you ask is to pass the variable value to a page from another and use it as the initial value instead of 0 in order to have a cumulative value instead; you could use the addEventListener and postMessage methods (see http://robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/, http://msdn.microsoft.com/en-us/library/bb979674(v=VS.95).aspx and http://stackoverflow.com/questions/256754/how-to-pass-arguments-to-addeventlistener-listener-function).
0
 

Author Comment

by:crm624
ID: 38879051
I was able to pass the value of a timer I made and use cookies to start from where it left off.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

856 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