You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3-frames-and-windows/03-cross-window-communication/article.md
+46-46Lines changed: 46 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,130 +1,130 @@
1
-
# Cross-window communication
1
+
# Comuniaczione cross-window
2
2
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.
4
4
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.
6
6
7
7
## Same Origin [#same-origin]
8
8
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.
10
10
11
-
These URLs all share the same origin:
11
+
Ad esempio, questi URL condividono la stessa origine:
-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).
28
28
29
-
### In action: iframe
29
+
### In azione: iframe
30
30
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.
32
32
33
-
We can access them using properties:
33
+
Possiamo accedervi utilizzando le proprietà:
34
34
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`.
37
37
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).
39
39
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:
```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.
101
101
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`.
103
103
```
104
104
105
-
## Windows on subdomains: document.domain
105
+
## Finestre di sotto-domini: document.domain
106
106
107
-
By definition, two URLs with different domains have different origins.
107
+
Per definizione, due URL con domini differenti appartengono ad origini differenti.
108
108
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.
110
110
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:
112
112
113
113
```js
114
114
document.domain = 'site.com';
115
115
```
116
116
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.
118
118
119
-
## Iframe: wrong document pitfall
119
+
## Iframe: il tranello del document errato
120
120
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.
122
122
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!
124
124
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.
126
126
127
-
Here, look:
127
+
Vediamo un esempio di quanto affermato:
128
128
129
129
130
130
```html run
@@ -135,7 +135,7 @@ Here, look:
135
135
iframe.onload=function() {
136
136
let newDoc =iframe.contentDocument;
137
137
*!*
138
-
//the loaded document is not the same as initial!
138
+
//il document caricato non equivale a quello iniziale!
0 commit comments