Skip to content

Commit 5f61e52

Browse files
committed
translated first part
1 parent 139c9f0 commit 5f61e52

File tree

1 file changed

+46
-46
lines changed
  • 3-frames-and-windows/03-cross-window-communication

1 file changed

+46
-46
lines changed

3-frames-and-windows/03-cross-window-communication/article.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,130 @@
1-
# Cross-window communication
1+
# Comuniaczione cross-window
22

3-
The "Same Origin" (same site) policy limits access of windows and frames to each other.
3+
La politcia di "Same Origin" ("stessa origine", ovvero stesso sito) limita il reciproco accesso tra finestre ed iframe diversi.
44

5-
The idea is that if a user has two pages open: one from `john-smith.com`, and another one is `gmail.com`, then they wouldn't want a script from `john-smith.com` to read our mail from `gmail.com`. So, the purpose of the "Same Origin" policy is to protect users from information theft.
5+
L'idea è che, se un utente ha deu pagine aperte: una su `john-smith.com`, ed un'altra su `gmail.com`, allora non vorrà che uno script ion esecuzione su `john-smith.com` possa leggere tutte le sue mail dalla finestra di `gmail.com`. Quindi, lo scopo della politica "Same Origin" è quello di proteggere l'utente dal furto di informazioni.
66

77
## Same Origin [#same-origin]
88

9-
Two URLs are said to have the "same origin" if they have the same protocol, domain and port.
9+
Due URL vengono definiti come appartenenti alla "stessa origine" solo se possiedono lo stesso protocollo, dominio e porta.
1010

11-
These URLs all share the same origin:
11+
Ad esempio, questi URL condividono la stessa origine:
1212

1313
- `http://site.com`
1414
- `http://site.com/`
1515
- `http://site.com/my/page.html`
1616

17-
These ones do not:
17+
Questi invece no:
1818

19-
- <code>http://<b>www.</b>site.com</code> (another domain: `www.` matters)
20-
- <code>http://<b>site.org</b></code> (another domain: `.org` matters)
21-
- <code><b>https://</b>site.com</code> (another protocol: `https`)
22-
- <code>http://site.com:<b>8080</b></code> (another port: `8080`)
19+
- <code>http://<b>www.</b>site.com</code> (dominio differente: `www.` è diverso)
20+
- <code>http://<b>site.org</b></code> (dominio differente: `.org` è diverso)
21+
- <code><b>https://</b>site.com</code> (protocollo differente: `https`)
22+
- <code>http://site.com:<b>8080</b></code> (porta differente: `8080`)
2323

24-
The "Same Origin" policy states that:
24+
La politica di "Same Origin" afferma che:
2525

26-
- if we have a reference to another window, e.g. a popup created by `window.open` or a window inside `<iframe>`, and that window comes from the same origin, then we have full access to that window.
27-
- otherwise, if it comes from another origin, then we can't access the content of that window: variables, document, anything. The only exception is `location`: we can change it (thus redirecting the user). But we cannot *read* location (so we can't see where the user is now, no information leak).
26+
- se abbiamo un riferimento ad un'altra finestra, ad esempio un popup creato tramite `window.open` oppure una finestra all'interno di un `<iframe>`, e queste finestre appartengono alla stessa origine, allora avremo pieno accesso ad esse.
27+
- altrimenti, se queste provengono da origini differenti, allora non potremo accedere al cotenuto della finestra: variables, il suo document, e qualsiasi altra informazione. L'unica eccezione è sulla proprietà `location`: possiamo modificarla (reindirizzando l'utente). Ma non possiamo *leggerne* il contenuto (quindi non possiamo sapere in quale sito si trova l'utente in un dato momento, nessuna infromazione viene trapelata).
2828

29-
### In action: iframe
29+
### In azione: iframe
3030

31-
An `<iframe>` tag hosts a separate embedded window, with its own separate `document` and `window` objects.
31+
Un tag di `<iframe>` permette di incorporare una finestra separata, la quale avrà i suoi oggetti `document` e `window` separati.
3232

33-
We can access them using properties:
33+
Possiamo accedervi utilizzando le proprietà:
3434

35-
- `iframe.contentWindow` to get the window inside the `<iframe>`.
36-
- `iframe.contentDocument` to get the document inside the `<iframe>`, shorthand for `iframe.contentWindow.document`.
35+
- `iframe.contentWindow` per ottenere il riferiemnto alla finestra all'interno di `<iframe>`.
36+
- `iframe.contentDocument` per ottenere il riferimento al document all'interno di `<iframe>`, abbreviazione per `iframe.contentWindow.document`.
3737

38-
When we access something inside the embedded window, the browser checks if the iframe has the same origin. If that's not so then the access is denied (writing to `location` is an exception, it's still permitted).
38+
Quando accediamo a qualche proprietà della finestra incorporata, il browser verificherà se l'iframe appartiene alla stessa origine. Se cosi non è, allora l'accesso verrà negatp (rimane l'eccezione sulla scrittura di `location`, che è comunque permessa).
3939

40-
For instance, let's try reading and writing to `<iframe>` from another origin:
40+
Ad esempio, proviamo a leggere e scrivere su un `<iframe>` da un'altra origine:
4141

4242
```html run
4343
<iframe src="https://example.com" id="iframe"></iframe>
4444

4545
<script>
4646
iframe.onload = function() {
47-
// we can get the reference to the inner window
47+
// possiamo ottenere il riferiemento alla finestra integrata
4848
*!*
4949
let iframeWindow = iframe.contentWindow; // OK
5050
*/!*
5151
try {
52-
// ...but not to the document inside it
52+
// ...ma non al suo document
5353
*!*
5454
let doc = iframe.contentDocument; // ERROR
5555
*/!*
5656
} catch(e) {
57-
alert(e); // Security Error (another origin)
57+
alert(e); // Security Error (origine diversa)
5858
}
5959
60-
// also we can't READ the URL of the page in iframe
60+
// non possiamo nemmeno LEGGERE l'URL di un iframe
6161
try {
62-
// Can't read URL from the Location object
62+
// Non possiamo leggere l'URL dall'oggetto Location
6363
*!*
6464
let href = iframe.contentWindow.location.href; // ERROR
6565
*/!*
6666
} catch(e) {
6767
alert(e); // Security Error
6868
}
6969
70-
// ...we can WRITE into location (and thus load something else into the iframe)!
70+
// ...possiamo però SCRIVERE sulla proprietà location (e questo caricherà un'altra pagina nell'iframe)!
7171
*!*
7272
iframe.contentWindow.location = '/'; // OK
7373
*/!*
7474
75-
iframe.onload = null; // clear the handler, not to run it after the location change
75+
iframe.onload = null; // ripuliamo l'handler, per evitare che venga eseguito dopo il cambio di location
7676
};
7777
</script>
7878
```
7979

80-
The code above shows errors for any operations except:
80+
Il codice sopra genera errori in tutti i casi ad eccezione di:
8181

82-
- Getting the reference to the inner window `iframe.contentWindow` - that's allowed.
83-
- Writing to `location`.
82+
- Lettura del riferimento alla finestra interna `iframe.contentWindow`, la quale è permessa.
83+
- Scrittura su `location`.
8484

85-
Contrary to that, if the `<iframe>` has the same origin, we can do anything with it:
85+
Contrariamente a questo, se l'`<iframe>` proviene dalla stessa origine, possiamo farci qualsiasi cosa:
8686

8787
```html run
88-
<!-- iframe from the same site -->
88+
<!-- iframe dallo stesso sito -->
8989
<iframe src="/" id="iframe"></iframe>
9090

9191
<script>
9292
iframe.onload = function() {
93-
// just do anything
93+
// qualsiasi operazione
9494
iframe.contentDocument.body.prepend("Hello, world!");
9595
};
9696
</script>
9797
```
9898

9999
```smart header="`iframe.onload` vs `iframe.contentWindow.onload`"
100-
The `iframe.onload` event (on the `<iframe>` tag) is essentially the same as `iframe.contentWindow.onload` (on the embedded window object). It triggers when the embedded window fully loads with all resources.
100+
L'evento di `iframe.onload` (nel tag `<iframe>`) equivale a `iframe.contentWindow.onload` (nell'oggetto della finestra incorporata). Si innesca quando la finestra integrata completaa il caricamento con tutte le risorse.
101101

102-
...But we can't access `iframe.contentWindow.onload` for an iframe from another origin, so using `iframe.onload`.
102+
...Ma non possiamo accedere a `iframe.contentWindow.onload` per un iframe che appartiene ad un'altra origine, utilizzando `iframe.onload`.
103103
```
104104
105-
## Windows on subdomains: document.domain
105+
## Finestre di sotto-domini: document.domain
106106
107-
By definition, two URLs with different domains have different origins.
107+
Per definizione, due URL con domini differenti appartengono ad origini differenti.
108108
109-
But if windows share the same second-level domain, for instance `john.site.com`, `peter.site.com` and `site.com` (so that their common second-level domain is `site.com`), we can make the browser ignore that difference, so that they can be treated as coming from the "same origin" for the purposes of cross-window communication.
109+
Ma se le due finestre condividono lo stesso dominio di secondo livello, ad esempio `john.site.com`, `peter.site.com` e `site.com` (il loro dominio di secondo livello comunue è `site.com`), possiamo far si che il browser ignori la differenza, in questo modo verrannop trattate come se provenissero dalla "stessa origine", per gli scopi della comunicazione tra finestre.
110110
111-
To make it work, each such window should run the code:
111+
Per far si che questo funzioni, ogni finestra dovrà eseguire il seguente codice:
112112
113113
```js
114114
document.domain = 'site.com';
115115
```
116116

117-
That's all. Now they can interact without limitations. Again, that's only possible for pages with the same second-level domain.
117+
Questo è tutto. Da questo momento in poi potranno interagire senza limitazioni. Nuovamente, questo è possibile solamente per pagine che possiedono lo stesso dominio di secondo livello.
118118

119-
## Iframe: wrong document pitfall
119+
## Iframe: il tranello del document errato
120120

121-
When an iframe comes from the same origin, and we may access its `document`, there's a pitfall. It's not related to cross-origin things, but important to know.
121+
Quando un iframe appartine alla stessa origine, con la possibilità quindi di accere al suo `document`, c'è un piccolo tranello a cui prestare attenzione. Non è strettamente legato al cross-origin, ma è comunque importante esserne a consocenza.
122122

123-
Upon its creation an iframe immediately has a document. But that document is different from the one that loads into it!
123+
Al momento della creazione, un iframe genera immediatamente un docuement. Ma quest utlimo è diverso da quello che verrà caricato internamente!
124124

125-
So if we do something with the document immediately, that will probably be lost.
125+
Quindi, se qualsiasi operazione effettuata sul document negli istanti dopo al creazione, andrà probabilmente persa.
126126

127-
Here, look:
127+
Vediamo un esempio di quanto affermato:
128128

129129

130130
```html run
@@ -135,7 +135,7 @@ Here, look:
135135
iframe.onload = function() {
136136
let newDoc = iframe.contentDocument;
137137
*!*
138-
// the loaded document is not the same as initial!
138+
// il document caricato non equivale a quello iniziale!
139139
alert(oldDoc == newDoc); // false
140140
*/!*
141141
};

0 commit comments

Comments
 (0)