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
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -142,40 +142,40 @@ Vediamo un esempio di quanto affermato:
142
142
</script>
143
143
```
144
144
145
-
We shouldn't work with the document of a not-yet-loaded iframe, because that's the *wrong document*. If we set any event handlers on it, they will be ignored.
145
+
Dovremmo evitare di effettuare operazioni sul document di un iframe non ancora completamente caricato, poiché questo è il *document sbagliato*. Qualsiasi gestore di evento ad esso collegato, verrà ignorato.
146
146
147
-
How to detect the moment when the document is there?
147
+
Come possiamo assicurarci che il document sia quello corretto?
148
148
149
-
The right document is definitely at place when `iframe.onload` triggers. But it only triggers when the whole iframe with all resources is loaded.
149
+
Per essere sicuri di lavorare con il document corretto, dovremmo attendere fin quando verrà emesso l'evento `iframe.onload`. Il quale verrà innescato solemente una volta che l'iframe avrà caricato tutte le risorse.
150
150
151
-
We can try to catch the moment earlier using checks in`setInterval`:
151
+
Possiamo provare ad intercettarlo anticipatamente effettuando controlli all'interno di un`setInterval`:
152
152
153
153
```html run
154
154
<iframesrc="/"id="iframe"></iframe>
155
155
156
156
<script>
157
157
let oldDoc =iframe.contentDocument;
158
158
159
-
//every 100 ms check if the document is the new one
159
+
//ogni 100ms verifichiamo se è stato generato il nuovo document
160
160
let timer =setInterval(() => {
161
161
let newDoc =iframe.contentDocument;
162
162
if (newDoc == oldDoc) return;
163
163
164
164
alert("New document is here!");
165
165
166
-
clearInterval(timer); //cancel setInterval, don't need it any more
166
+
clearInterval(timer); //cancelliamo il setInterval, non ne abbiamo più bisogno
167
167
}, 100);
168
168
</script>
169
169
```
170
170
171
171
## Collection: window.frames
172
172
173
-
An alternative way to get a window object for `<iframe>` -- is to get it from the named collection`window.frames`:
173
+
Un modo alternativo per ottenere l'oggetto realtivo ad una finestra di `<iframe>`, è quello di accedervi tramite la collection `window.frames`:
174
174
175
-
-By number: `window.frames[0]` -- the window object for the first frame in the document.
176
-
- By name: `window.frames.iframeName` -- the window object for the frame with `name="iframeName"`.
175
+
-Tramite indice: `window.frames[0]`: l'oggetto relativo alla prima finestra di iframe nel document.
176
+
- By name: `window.frames.iframeName`: l'oggetto realtivo all'iframew con`name="iframeName"`.
An iframe may have other iframes inside. The corresponding `window`objects form a hierarchy.
189
+
Un iframe potrebbe possedere a sua volta degli iframe. I rispettivi oggetti `window`formeranno una gerarchia.
190
190
191
-
Navigation links are:
191
+
E' possibile navigare tra le finestre della gerarchia utilizzando:
192
192
193
-
-`window.frames` -- the collection of "children" windows (for nested frames).
194
-
-`window.parent` -- the reference to the "parent" (outer) window.
195
-
-`window.top` -- the reference to the topmost parent window.
193
+
-`window.frames`: la collezione delle finestre "figlie" (per iframe annidati).
194
+
-`window.parent`: il riferimento alla finestra "padre" (quella esterna).
195
+
-`window.top`: il riferiemento alla finestra in cima alla gerarchia.
196
196
197
-
For instance:
197
+
Ad esempio:
198
198
199
199
```js run
200
200
window.frames[0].parent===window; // true
201
201
```
202
202
203
-
We can use the`top`property to check if the current document is open inside a frame or not:
203
+
Possiamo utilizzare la proprietà`top`per verificare se il document corrente è aperto all'interno di un iframe o no:
204
204
205
205
```js run
206
-
if (window== top) { //current window == window.top?
206
+
if (window== top) { // window == window.top?
207
207
alert('The script is in the topmost window, not in a frame');
208
208
} else {
209
209
alert('The script runs in a frame!');
210
210
}
211
211
```
212
212
213
-
## The "sandbox" iframe attribute
213
+
## L'attributo "sandbox" per iframe
214
214
215
215
The `sandbox` attribute allows for the exclusion of certain actions inside an `<iframe>` in order to prevent it executing untrusted code. It "sandboxes" the iframe by treating it as coming from another origin and/or applying other limitations.
0 commit comments