Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The Storage object (both localStorage and sessionStorage) is available from all tabs having the same page open.</p> <p>However (some comment state this is not correct, but this is a misinterpretation of the documentation), when you open a new tab a new storage object is created internally. This is a <strong>clone</strong> of the first one so the content at that point is the same.</p> <p>They are treated separate from that point, but you synchronize them by listening to the <code>storage</code> <a href="http://dev.w3.org/html5/webstorage/#send-a-storage-notification">event</a> in your code.</p> <p>From <a href="http://dev.w3.org/html5/webstorage/#the-sessionstorage-attribute">http://dev.w3.org/html5/webstorage/#the-sessionstorage-attribute</a>: (note that the specs are addressing the implementers)</p> <blockquote> <p>When a new top-level browsing context is created by cloning an existing browsing context, the new browsing context must start with the same session storage areas as the original, but the two sets must from that point on be considered separate, not affecting each other in any way. [...] When the setItem(), removeItem(), and clear() methods are called on a Storage object x that is associated with a session storage area [...], <strong>then for every Document object whose Window object's sessionStorage attribute's Storage object is associated with the same storage area, other than x, send a storage notification</strong>.</p> </blockquote> <p>That is to say that when a storage is modified in the active tab, a <code>storage</code> event is sent to all the other tabs (for the same origin) - but not the active tab which of course isn't needed as this is the one being modified.</p> <p>Use the <a href="http://dev.w3.org/html5/webstorage/#send-a-storage-notification">event</a> to read the <code>key</code> and <code>newValue</code> fields to update the <code>localSession</code> in the currently <em>inactive</em> tab(s) (there is also the <code>oldValue</code> on the event). The <code>storageArea</code> contains the Storage object that is affected (useful if you use both local and session storage).</p> <p>As to "one domain" - yes, the same data will only be available to the same <em>origin</em> (scheme, domain and port).</p> <p>Sending the data to server is fully possible. Everything stored in Storage (session and local) is stored as a string. I would recommend encoding it though (JSON is <em>not</em> necessary as it is already stored as a string). Use f.ex:</p> <pre><code>var dataForServer = encodeURIComponent(sessionStorage.getItem(myKey)); </code></pre> <p>Then send it as part of a form, url or by ajax.</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. VO
      singulars
      1. This table or related slice is empty.
    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