Tuesday, June 4, 2024
0
rated 0 times [  2] [ 2]  / answers: 1 / hits: 18272  / 7 Years ago, mon, april 3, 2017, 12:00:00

I am using sessionStorage to ensure an action only happens once per session. However, if a user opens a new window - the sessionStorage is not carried over to the new window, and the action is executed again. See my code below:



if sessionStorage.alreadyTracked != 1
sessionStorage.alreadyTracked = 1
...


Is there an easy way to do this that applies to all tabs? Maybe I need to use a cookie?


More From » session-variables

 Answers
6

As far as html5 storage goes i would go for localStorage in your case.



See below for the differences.



Session Storage:




  • Values persist only as long as the window or tab in which they

    stored.

  • Values are only visible within the window or tab that
    created them.



Local Storage:




  • Values persist window and browser lifetimes.

  • Values are shared across every window or tab running at the same origin.



Read more here


[#58286] Saturday, April 1, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alexandreah

Total Points: 720
Total Questions: 85
Total Answers: 90

Location: Central African Republic
Member since Fri, Jun 5, 2020
4 Years ago
alexandreah questions
Mon, Aug 9, 21, 00:00, 3 Years ago
Wed, Jan 8, 20, 00:00, 5 Years ago
Mon, Dec 16, 19, 00:00, 5 Years ago
Fri, Sep 27, 19, 00:00, 5 Years ago
;