aboutsummaryrefslogtreecommitdiff
path: root/files/he/web/api/web_storage_api
diff options
context:
space:
mode:
Diffstat (limited to 'files/he/web/api/web_storage_api')
-rw-r--r--files/he/web/api/web_storage_api/index.html111
1 files changed, 111 insertions, 0 deletions
diff --git a/files/he/web/api/web_storage_api/index.html b/files/he/web/api/web_storage_api/index.html
new file mode 100644
index 0000000000..51a64e09b3
--- /dev/null
+++ b/files/he/web/api/web_storage_api/index.html
@@ -0,0 +1,111 @@
+---
+title: ממשק פיתוח היישומים Web Storage
+slug: Web/API/Web_Storage_API
+translation_of: Web/API/Web_Storage_API
+---
+<div style="direction: ltr !important;">{{DefaultAPISidebar("Web Storage API")}}</div>
+
+<p>The <strong>Web Storage API</strong> provides mechanisms by which browsers can store key/value pairs, in a much more intuitive fashion than using {{glossary("cookie", "cookies")}}.</p>
+
+<h2 id="Web_Storage_concepts_and_usage">Web Storage concepts and usage</h2>
+
+<p>The two mechanisms within Web Storage are as follows:</p>
+
+<ul>
+ <li><code>sessionStorage</code> maintains a separate storage area for each given origin that's available for the duration of the page session (as long as the browser is open, including page reloads and restores)
+
+ <ul>
+ <li>Stores data only for a session, meaning that the data is stored until the browser (or tab) is closed.</li>
+ <li>Data is never transferred to the server.</li>
+ <li>Storage limit is larger than a cookie (at most 5MB).</li>
+ </ul>
+ </li>
+ <li><code>localStorage</code> does the same thing, but persists even when the browser is closed and reopened.
+ <ul>
+ <li>Stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser cache / Locally Stored Data.</li>
+ <li>Storage limit is the maximum amongst the three.</li>
+ </ul>
+ </li>
+</ul>
+
+<p>These mechanisms are available via the {{domxref("Window.sessionStorage")}} and {{domxref("Window.localStorage")}} properties (to be more precise, in supporting browsers the <code>Window</code> object implements the <code>WindowLocalStorage</code> and <code>WindowSessionStorage</code> objects, which the <code>localStorage</code> and <code>sessionStorage</code> properties hang off) — invoking one of these will create an instance of the {{domxref("Storage")}} object, through which data items can be set, retrieved and removed. A different Storage object is used for the <code>sessionStorage</code> and <code>localStorage</code> for each origin — they function and are controlled separately.</p>
+
+<div class="note">
+<p><strong>Note</strong>: From Firefox 45 onwards, when the browser crashes/restarts, the amount of data saved per origin is limited to 10MB. This has been done to avoid memory issues caused by excessive usage of web storage.</p>
+</div>
+
+<div class="note">
+<p><strong>Note</strong>: Access to Web Storage from third-party IFrames is denied if the user has <a href="https://support.mozilla.org/en-US/kb/disable-third-party-cookies">disabled third-party cookies</a> (Firefox implements this behaviour from <a href="/en-US/docs/Mozilla/Firefox/Releases/43">version 43</a> onwards.)</p>
+</div>
+
+<div class="note">
+<p><strong>Note:</strong> Web Storage is not the same as <a href="/en-US/docs/Storage" title="Storage">mozStorage</a> (Mozilla's XPCOM interfaces to SQLite) or the <a href="/en-US/docs/Session_store_API" title="Session_store_API">Session store API</a> (an <a href="/en-US/docs/XPCOM" title="XPCOM">XPCOM</a> storage utility for use by extensions).</p>
+</div>
+
+<h2 id="Web_Storage_interfaces">Web Storage interfaces</h2>
+
+<dl>
+ <dt>{{domxref("Storage")}}</dt>
+ <dd>Allows you to set, retrieve and remove data for a specific domain and storage type (session or local.)</dd>
+ <dt>{{domxref("Window")}}</dt>
+ <dd>The Web Storage API extends the {{domxref("Window")}} object with two new properties — {{domxref("Window.sessionStorage")}} and {{domxref("Window.localStorage")}} — which provide access to the current domain's session and local {{domxref("Storage")}} objects respectively, and a {{domxref("Window.onstorage")}} event handler that fires when a storage area changes (e.g. a new item is stored.)</dd>
+ <dt>{{domxref("StorageEvent")}}</dt>
+ <dd>The <code title="event-storage">storage</code> event is fired on a document's <code>Window</code> object when a storage area changes.</dd>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<p>To illustrate some typical web storage usage, we have created a simple example, imaginatively called <a href="https://github.com/mdn/dom-examples/tree/master/web-storage">Web Storage Demo</a>. The <a href="https://mdn.github.io/dom-examples/web-storage/">landing page</a> provides controls that can be used to customize the colour, font and decorative image. When you choose different options, the page is instantly updated; in addition your choices are stored in <code>localStorage</code>, so that when you leave the page then load it again later on your choices are remembered.</p>
+
+<p>In addition, we have provided an <a href="https://mdn.github.io/dom-examples/web-storage/event.html">event output page</a> — if you load this page in another tab, then make changes to your choices in the landing page, you'll see the updated storage information outputted as the {{domxref("StorageEvent")}} is fired.</p>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('HTML WHATWG', 'webstorage.html#webstorage')}}</td>
+ <td>{{Spec2('HTML WHATWG')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<h3 id="Window.localStorage"><code>Window.localStorage</code></h3>
+
+<div>
+
+
+<p>{{Compat("api.Window.localStorage")}}</p>
+
+<h3 id="Window.sessionStorage"><code>Window.sessionStorage</code></h3>
+
+<div>
+<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div>
+
+<p>{{Compat("api.Window.sessionStorage")}}</p>
+</div>
+</div>
+
+<h2 id="Private_Browsing_Incognito_modes">Private Browsing / Incognito modes</h2>
+
+<p>Most modern browsers support a privacy option called 'Incognito', 'Private Browsing' or something similar that doesn't store data like history and cookies. This is fundamentally incompatible with Web Storage for obvious reasons. As such, browser vendors are experimenting with different scenarios for how to deal with this incompatibility.</p>
+
+<p>Most browsers have opted for a strategy where storage APIs are still available and seemingly fully functional, with the one big difference that all stored data is wiped after the browser is closed. For these browsers there are still different interpretations of what should be done with existing stored data (from a regular browsing session). Should it be available to read when in Private mode? Then there are some browsers, most notably Safari, that have opted for a solution where storage is available, but is empty and has a quota of 0 bytes assigned, effectively making it impossible to write data to it.</p>
+
+<p>Developers should be aware of these different implementations and take them into account when developing websites depending on Web Storage APIs. For more information please have a look at <a href="https://blog.whatwg.org/this-week-in-html-5-episode-30">this WHATWG blog post</a> that specifically deals with this topic.</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API">Using the Web Storage API</a></li>
+ <li><a href="/en-US/docs/Web/API/IndexedDB_API/Browser_storage_limits_and_eviction_criteria">Browser storage limits and eviction criteria</a></li>
+ <li><a href="https://medium.com/@ramsunvtech/onfocus-html5-storage-apis-b45d92aa424b">HTML5 Storage API By Venkatraman</a></li>
+</ul>