aboutsummaryrefslogtreecommitdiff
path: root/files/it/web/javascript/reference/global_objects/encodeuricomponent
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
commitda78a9e329e272dedb2400b79a3bdeebff387d47 (patch)
treee6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/it/web/javascript/reference/global_objects/encodeuricomponent
parent1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff)
downloadtranslated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip
initial commit
Diffstat (limited to 'files/it/web/javascript/reference/global_objects/encodeuricomponent')
-rw-r--r--files/it/web/javascript/reference/global_objects/encodeuricomponent/index.html162
1 files changed, 162 insertions, 0 deletions
diff --git a/files/it/web/javascript/reference/global_objects/encodeuricomponent/index.html b/files/it/web/javascript/reference/global_objects/encodeuricomponent/index.html
new file mode 100644
index 0000000000..66b290ccb4
--- /dev/null
+++ b/files/it/web/javascript/reference/global_objects/encodeuricomponent/index.html
@@ -0,0 +1,162 @@
+---
+title: encodeURIComponent()
+slug: Web/JavaScript/Reference/Global_Objects/encodeURIComponent
+translation_of: Web/JavaScript/Reference/Global_Objects/encodeURIComponent
+---
+<div>{{jsSidebar("Objects")}}</div>
+
+<h2 id="Summary" name="Summary">Sommario</h2>
+
+<p>La funzione <strong><code>encodeURIComponent()</code></strong> codifica un componente di un {{Glossary("URI")}} sostituendo alcuni specifici caratteri con una, due, tre o quattro sequenze di escape, che rappresentano il carattere codificato in {{Glossary("UTF-8")}} (le sequenze di quattro caratteri di escape verrano solo create per i caratteri composti da due caratteri "surrogati").</p>
+
+<h2 id="Syntax" name="Syntax">Sintassi</h2>
+
+<pre class="syntaxbox">encodeURIComponent(uriComponent);</pre>
+
+<h3 id="Parameters" name="Parameters">Parametri</h3>
+
+<dl>
+ <dt><code>uriComponent</code></dt>
+ <dd>Una parte di un {{Glossary("URI")}}</dd>
+</dl>
+
+<h2 id="Description" name="Description">Descrizione</h2>
+
+<p><code>encodeURIComponent</code> sostituisce tutti i caratteri esclusi i seguenti: lettere, cifre, <code>- _ . ! ~ * ' ( )</code></p>
+
+<p>Se si tenta di codificare un surrogato che non è parte di una coppia, verrà generato un {{jsxref("Global_Objects/URIError", "URIError")}}.</p>
+
+<pre class="brush: js">// Coppia surrogata: Ok
+encodeURIComponent("\uD800\uDFFF");
+
+// Solo il primo carattere surrogato:
+// Viene generato un "URIError: malformed URI sequence"
+encodeURIComponent("\uD800");
+
+// Solo il secondo carattere surrogato:
+// Viene generato un "URIError: malformed URI sequence"
+encodeURIComponent("\uDFFF");</pre>
+
+<p>Per evitare problemi inaspettati durante le richieste al server, bisognerebbe richiamare <code>encodeURIComponent</code> su ogni dato inserito dall'utente che verrà passato come parte di un {{Glossary("URI")}}. Per esempio, un un utente potrebbe digitare "<code>Cani&amp;Gatti = animali"</code>. Senza utilizzare la funzione <code>encodeURIComponent</code>, la richiesta verrebbe costruita in modo simile a "<code>commento=Cani&amp;Gatti%20=%20animali</code>". Notare che sono due variabili separate: "<code>commento</code>" e "<code>Gatti%20</code>". Utilizzando quuesta funzione verrebbe invece costruita come "<code>commento=Cani%26Gatti%20%3D%20animali​</code>".</p>
+
+<p>Utilizzando <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#application/x-www-form-urlencoded-encoding-algorithm"><code>application/x-www-form-urlencoded</code></a>, gli spazi devono essere sostituiti da un "<code>+</code>"., quindi si potrebbe usare la funzione <code>encodeURIComponent</code> seguita da un altra sostituzione da "<code>%20</code>" a "<code>+</code>".</p>
+
+<p>Per aderire con più precisione allo standard <a class="external" href="http://tools.ietf.org/html/rfc3986">RFC 3986</a> (secondo il quale <code>!</code>, <code>'</code>, <code>(</code>, <code>)</code> e <code>*</code> sono caratteri riservati), si può usare la seguente funzione:</p>
+
+<pre class="brush: js">function fixedEncodeURIComponent(str) {
+ return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
+ return '%' + c.charCodeAt(0).toString(16);
+ });
+}
+</pre>
+
+<h2 id="See_also" name="See_also">Esempi</h2>
+
+<p>Il seguente esempio fornisce un metodo per codificare come richiesto dall'header <code>Content-Disposition</code>:</p>
+
+<pre class="brush: js">var fileName = 'my file(2).txt';
+var header = "Content-Disposition: attachment; filename*=UTF-8''"
+ + encodeRFC5987ValueChars(fileName);
+
+console.log(header);
+// logs "Content-Disposition: attachment; filename*=UTF-8''my%20file%282%29.txt"
+
+
+function encodeRFC5987ValueChars (str) {
+    return encodeURIComponent(str).
+        // Notare che anche se per l'RFC3986 "!" è riservato, non lo è per
+ // l' RFC5987, quindi non viene sostituito
+        replace(/['()]/g, escape). // i.e., %27 %28 %29
+        replace(/\*/g, '%2A').
+            // Per l'RFC5987 questi caratteri non necessitano di essere codificati,
+ // quindi possiamo consentire un po' più di leggibilità: |`^
+            replace(/%(?:7C|60|5E)/g, unescape);
+}
+</pre>
+
+<h2 id="Specifiche">Specifiche</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specifica</th>
+ <th scope="col">Stato</th>
+ <th scope="col">Commenti</th>
+ </tr>
+ <tr>
+ <td>ECMAScript 3rd Edition.</td>
+ <td>Standard</td>
+ <td>Definizione iniziale.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.1.3.4', 'encodeURIComponent')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-encodeuricomponent-uricomponent', 'encodeURIComponent')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Compatibilità_con_i_browser">Compatibilità con i browser</h2>
+
+<p>{{CompatibilityTable}}</p>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Funzionalità</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Supporto di base</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th><span style="font-family: 'Open Sans Light', sans-serif; font-size: 16px; line-height: 16px;">Funzionalità</span></th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Supporto di base</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="Vedi_anche">Vedi anche</h2>
+
+<ul>
+ <li>{{jsxref("Global_Objects/decodeURI", "decodeURI()")}}</li>
+ <li>{{jsxref("Global_Objects/encodeURI", "encodeURI()")}}</li>
+ <li>{{jsxref("Global_Objects/decodeURIComponent", "decodeURIComponent()")}}</li>
+</ul>