Skip to content

Commit d81574a

Browse files
committed
translated second part
1 parent 5f61e52 commit d81574a

File tree

1 file changed

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

1 file changed

+19
-19
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -142,40 +142,40 @@ Vediamo un esempio di quanto affermato:
142142
</script>
143143
```
144144

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.
146146

147-
How to detect the moment when the document is there?
147+
Come possiamo assicurarci che il document sia quello corretto?
148148

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.
150150

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`:
152152

153153
```html run
154154
<iframe src="/" id="iframe"></iframe>
155155

156156
<script>
157157
let oldDoc = iframe.contentDocument;
158158
159-
// every 100 ms check if the document is the new one
159+
// ogni 100ms verifichiamo se è stato generato il nuovo document
160160
let timer = setInterval(() => {
161161
let newDoc = iframe.contentDocument;
162162
if (newDoc == oldDoc) return;
163163
164164
alert("New document is here!");
165165
166-
clearInterval(timer); // cancel setInterval, don't need it any more
166+
clearInterval(timer); // cancelliamo il setInterval, non ne abbiamo più bisogno
167167
}, 100);
168168
</script>
169169
```
170170

171171
## Collection: window.frames
172172

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`:
174174

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"`.
177177

178-
For instance:
178+
Ad esempio:
179179

180180
```html run
181181
<iframe src="/" style="height:80px" name="win" id="iframe"></iframe>
@@ -186,31 +186,31 @@ For instance:
186186
</script>
187187
```
188188

189-
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.
190190

191-
Navigation links are:
191+
E' possibile navigare tra le finestre della gerarchia utilizzando:
192192

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.
196196

197-
For instance:
197+
Ad esempio:
198198

199199
```js run
200200
window.frames[0].parent === window; // true
201201
```
202202

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:
204204

205205
```js run
206-
if (window == top) { // current window == window.top?
206+
if (window == top) { // window == window.top?
207207
alert('The script is in the topmost window, not in a frame');
208208
} else {
209209
alert('The script runs in a frame!');
210210
}
211211
```
212212

213-
## The "sandbox" iframe attribute
213+
## L'attributo "sandbox" per iframe
214214

215215
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.
216216

0 commit comments

Comments
 (0)