3 Years
Discussion Span
Last Post by piers

The scope of JavaScript code is per page so refreshing the page is like making the code start again - like switching it off and on again.

So if you want to persist some value - ie the state of your counter - then you will need to store it somewhere and load it up again when the page is loaded.

The counter needs to be per user of course otherwise everyone will get the same value! So one option could be a cookie and another could be to store it on a server somewhere but that depends what technologies you are using, is your user signed in etc.

Reading and writing cookies with JavaScript - http://www.w3schools.com/js/js_cookies.asp

Hope that helps.

Edited by DaveAmour


Or load your pages dynamically via AJAX (plus HTML5 History API) in a container (div) and place the counter oustide this container.

Look at this demo. Audio player keeps on playing and URL changes while navigating between content. This library really rocks!


Edited by gentlemedia

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.