The only limitation with the code below is that a web browsers caching behavior make the method below not 100% reliable ...
An even better way is to use the sessionStorage
object of javascript which only persists until the person leaves the page, no matter what the web browsers caching policy.