Skip to content

Commit 54a8d6a

Browse files
line 105
1 parent 181832e commit 54a8d6a

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

  • 3-frames-and-windows/03-cross-window-communication

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,63 @@ For instance, let's try reading and writing to `<iframe>` from another origin:
4545

4646
<script>
4747
iframe.onload = function() {
48-
// we can get the reference to the inner window
48+
// می‌توانیم ارجاع‌ها به پنجره‌ی درونی را بگیریم
4949
*!*
5050
let iframeWindow = iframe.contentWindow; // OK
5151
*/!*
5252
try {
53-
// ...but not to the document inside it
53+
// ... داخل آن نه document اما
5454
*!*
5555
let doc = iframe.contentDocument; // ERROR
5656
*/!*
5757
} catch(e) {
58-
alert(e); // Security Error (another origin)
58+
alert(e); // خطای امنیتی (یک منبع دیگر)
5959
}
6060
61-
// also we can't READ the URL of the page in iframe
61+
// را بخوانیم iframe یک صفحه درون URL همچنین ما نمی‌توانیم
6262
try {
63-
// Can't read URL from the Location object
63+
// بخوانیم Location object را از URL نمی‌توانیم
6464
*!*
6565
let href = iframe.contentWindow.location.href; // ERROR
6666
*/!*
6767
} catch(e) {
6868
alert(e); // Security Error
6969
}
7070
71-
// ...we can WRITE into location (and thus load something else into the iframe)!
71+
// ... !(بارگذاری کنیم iframe و در نتیجه چیز دیگری را) بنویسیم location ما می‌توانیم بر
7272
*!*
7373
iframe.contentWindow.location = '/'; // OK
7474
*/!*
7575
76-
iframe.onload = null; // clear the handler, not to run it after the location change
76+
iframe.onload = null; // آن را اجرا کند location را پاک می‌کند، نه اینکه بعد از تغییر handler این
77+
7778
};
7879
</script>
7980
```
8081

81-
The code above shows errors for any operations except:
82+
کد بالا خطاهای هر عملیاتی را نشان می‌هد به جز:
8283

83-
- Getting the reference to the inner window `iframe.contentWindow` - that's allowed.
84-
- Writing to `location`.
84+
- گرفتن ارجاع به پنجره‌ی درونی `iframe.contentWindow` - آن مجاز است.
85+
- نوشتن برا `location`
8586

86-
Contrary to that, if the `<iframe>` has the same origin, we can do anything with it:
87+
بر خلاف آن، اگر `<iframe>` منبع یکسانی داشته باشد،‌ ما می‌توانیم با آن هر کاری بکنیم:
8788

8889
```html run
8990
<!-- iframe from the same site -->
9091
<iframe src="/" id="iframe"></iframe>
9192

9293
<script>
9394
iframe.onload = function() {
94-
// just do anything
95+
// هر کاری می‌کند
9596
iframe.contentDocument.body.prepend("Hello, world!");
9697
};
9798
</script>
9899
```
99100

100-
```smart header="`iframe.onload` vs `iframe.contentWindow.onload`"
101-
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.
101+
```smart header="`iframe.onload` در مقابل `iframe.contentWindow.onload`"
102+
اساسا `iframe.onload` event (در تگ `<iframe>`) همان `iframe.contentWindow.onload` (در شی پنجره‌ی جداسازی‌شده)‌ است. وقتی که پنجره‌ی جاسازی شده به طور کامل با تمام منابع load می‌شود، فعال می‌شود.
102103

103-
...But we can't access `iframe.contentWindow.onload` for an iframe from another origin, so using `iframe.onload`.
104+
...اما نمی‌توانیم به `iframe.contentWindow.onload` برای یک iframe از مبدا دیگری دسترسی پیدا کنیم،‌بنابراین از `iframe.onload` استفاده می‌کنیم.
104105
```
105106
106107
## Windows on subdomains: document.domain

0 commit comments

Comments
 (0)