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
همهاش همین است. حالا آنها میتوانند بدون محدودیت با هم تعامل داشته باشند. باز هم، این فقط برای صفحاتی با همان دامنهی سطح دوم امکان پذیر است.
118
118
119
119
```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) است. پیام دادن بین پنجرهای (به زودی در زیر توضیح داده میشود) جایگزین پیشنهادی است.
121
121
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` متکی هستند.
123
123
```
124
124
125
125
126
-
## Iframe: wrong document pitfall
126
+
## Iframe: تلهی اشتباه document
127
127
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` آن دسترسی پیدا کنیم، یک تله وجود دارد. این به چیزهای متقاطع مربوط نیست، اما مهم است که بدانید.
129
129
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ای که در آن بارگذاری میشود متفاوت است!
131
131
132
-
So if we do something with the document immediately, that will probably be lost.
132
+
بنابراین اگر فورا با document کاری انجام دهیم، احتمالا از بین خواهد رفت.
133
133
134
-
Here, look:
134
+
اینجا، نگاه کنید:
135
135
136
136
137
137
```html run
@@ -142,35 +142,35 @@ Here, look:
142
142
iframe.onload=function() {
143
143
let newDoc =iframe.contentDocument;
144
144
*!*
145
-
//the loaded document is not the same as initial!
145
+
//!بارگذاری شده مشابه اولیه نیست document
146
146
alert(oldDoc == newDoc); // false
147
147
*/!*
148
148
};
149
149
</script>
150
150
```
151
151
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ای تنظیم کنیم، نادیده گرفته خواهند شد.
153
153
154
-
How to detect the moment when the document is there?
154
+
چگونه میتوان لحظهای که document وجود دارد را تشخیص داد؟
155
155
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 با تمام منابعش بارگذاری شود.
157
157
158
-
We can try to catch the moment earlier using checks in `setInterval`:
158
+
میتوانیم با استفاده از چکهای `setInterval` آن لحظه را زودتر بگیریم:
159
159
160
160
```html run
161
161
<iframesrc="/"id="iframe"></iframe>
162
162
163
163
<script>
164
164
let oldDoc =iframe.contentDocument;
165
165
166
-
//every 100 ms check if the document is the new one
166
+
//جدید باشد document هر 100 میلیثانیه چک میکند که
167
167
let timer =setInterval(() => {
168
168
let newDoc =iframe.contentDocument;
169
169
if (newDoc == oldDoc) return;
170
170
171
-
alert("New document is here!");
171
+
alert("!جدید اینجا است document");
172
172
173
-
clearInterval(timer); //cancel setInterval, don't need it any more
173
+
clearInterval(timer); //را کنسل میکند، دیگر به آن نیازی نیست setInterval
0 commit comments