Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Local Storage will work for what you are trying to do better than cookies. Basically, there is an array-like object on the window called <code>localStorage</code>. You can use it to store arbitrary <strong>strings</strong> only. Like:</p> <pre><code>window.localStorage["button1_is_showing"] = true; </code></pre> <p>or:</p> <pre><code>window.localstorage.button1_is_showing = true; </code></pre> <p>The <code>true</code> boolean value will be turned into the string <code>"true"</code>. To turn it into a boolean again some time later:</p> <pre><code>var b1showing; if (window.localStorage.button1_is_showing == "true") { b1showing = true; } else { b1showing = false; } </code></pre> <p>You could also use the browser's JSON parser for this:</p> <pre><code>var b1showing = JSON.parse(window.localStorage.button1_is_showing); </code></pre> <p>But bear in mind that that does not have strong browser support: <a href="http://caniuse.com/#search=JSON" rel="nofollow">http://caniuse.com/#search=JSON</a></p> <p>Whatever strings you store in localStorage will stay there until the browser clears its cookies, or until you delete something like this:</p> <pre><code>delete window.localStorage.b1showing; </code></pre> <p>For your particular example: every time the user clicks a button, create one object in localStorage for each button that will store the buttons state. Then, when the page is loaded (in your ready event), loop through the localstorage checking what is there and hide/show the buttons depending on that.</p> <p>A side note: using classes instead of 7 different ids is much more flexible, readable, and fast.</p> <p>EDIT: Another excellent source: <a href="http://diveintohtml5.info/storage.html" rel="nofollow">http://diveintohtml5.info/storage.html</a></p> <p>Tons more info here: <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload