Skip to content

Commit cc097c1

Browse files
line 177
1 parent 4ac9431 commit cc097c1

1 file changed

Lines changed: 16 additions & 16 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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ For instance, let's try reading and writing to `<iframe>` from another origin:
9191
<script>
9292
iframe.onload = function() {
9393
// هر کاری می‌کند
94-
iframe.contentDocument.body.prepend("Hello, world!");
94+
iframe.contentDocument.body.prepend("سلام، دنیا");
9595
};
9696
</script>
9797
```
@@ -117,21 +117,21 @@ document.domain = 'site.com';
117117
همه‌اش همین است. حالا آن‌ها می‌توانند بدون محدودیت با هم تعامل داشته باشند. باز هم، این فقط برای صفحاتی با همان دامنه‌ی سطح دوم امکان پذیر است.
118118

119119
```warn header="منسوخ شده، اما همچنان کار می‌کند"
120-
The `document.domain` property is in the process of being removed from the [specification](https://html.spec.whatwg.org/multipage/origin.html#relaxing-the-same-origin-restriction). The cross-window messaging (explained soon below) is the suggested replacement.
120+
امروزه `document.domain` property در حال حذف از [مشخصات](https://html.spec.whatwg.org/multipage/origin.html#relaxing-the-same-origin-restriction) است. پیام دادن بین پنجره‌ای (به زودی در زیر توضیح داده می‌شود) جایگزین پیشنهادی است.
121121
122-
That said, as of now all browsers support it. And the support will be kept for the future, not to break old code that relies on `document.domain`.
122+
گقته می‌شود تا کنون تمام مرورگرها از آن پشتیبانی می‌کنند. و پشتیبانی برای آینده حفظ خواهد شد، نه برای شکستن کدهای قدیمی که به `document.domain` متکی هستند.
123123
```
124124

125125

126-
## Iframe: wrong document pitfall
126+
## Iframe: تله‌ی اشتباه document
127127

128-
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.
128+
وقتی یک iframe از همان منبع می‌آید، و ما ممکن است به `document` آن دسترسی پیدا کنیم، یک تله وجود دارد. این به چیزهای متقاطع مربوط نیست، اما مهم است که بدانید.
129129

130-
Upon its creation an iframe immediately has a document. But that document is different from the one that loads into it!
130+
به محض ایجاد یک iframe بلافاصله یک document دارد. اما آن document با documentای که در آن بارگذاری می‌شود متفاوت است!
131131

132-
So if we do something with the document immediately, that will probably be lost.
132+
بنابراین اگر فورا با document کاری انجام دهیم، احتمالا از بین خواهد رفت.
133133

134-
Here, look:
134+
اینجا، نگاه کنید:
135135

136136

137137
```html run
@@ -142,35 +142,35 @@ Here, look:
142142
iframe.onload = function() {
143143
let newDoc = iframe.contentDocument;
144144
*!*
145-
// the loaded document is not the same as initial!
145+
// !بارگذاری شده مشابه اولیه نیست document
146146
alert(oldDoc == newDoc); // false
147147
*/!*
148148
};
149149
</script>
150150
```
151151

152-
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.
152+
ما نباید با document یک iframe که هنوز بارگذاری نشده است کار کنیم، زیرا آن *docment اشتباه* است. اگر روی آن هر event handlerای تنظیم کنیم، نادیده گرفته خواهند شد.
153153

154-
How to detect the moment when the document is there?
154+
چگونه می‌توان لحظه‌ای که document وجود دارد را تشخیص داد؟
155155

156-
The right document is definitely at place when `iframe.onload` triggers. But it only triggers when the whole iframe with all resources is loaded.
156+
وقتی `iframe.onload` راه‌اندازی می‌شود، قطعا document مناسب در محل قرار می‌گیرد. اما فقط زمانی فعال می‌شود که کل iframe با تمام منابعش بارگذاری شود.
157157

158-
We can try to catch the moment earlier using checks in `setInterval`:
158+
می‌توانیم با استفاده از چک‌های `setInterval` آن لحظه را زودتر بگیریم:
159159

160160
```html run
161161
<iframe src="/" id="iframe"></iframe>
162162

163163
<script>
164164
let oldDoc = iframe.contentDocument;
165165
166-
// every 100 ms check if the document is the new one
166+
// جدید باشد document هر 100 میلی‌ثانیه چک می‌کند که
167167
let timer = setInterval(() => {
168168
let newDoc = iframe.contentDocument;
169169
if (newDoc == oldDoc) return;
170170
171-
alert("New document is here!");
171+
alert("!جدید اینجا است document");
172172
173-
clearInterval(timer); // cancel setInterval, don't need it any more
173+
clearInterval(timer); // را کنسل می‌کند، دیگر به آن نیازی نیست setInterval
174174
}, 100);
175175
</script>
176176
```

0 commit comments

Comments
 (0)