|
1 | | -# Cross-window communication |
| 1 | +# ارتباط بین پنجرهای |
2 | 2 |
|
3 | | -The "Same Origin" (same site) policy limits access of windows and frames to each other. |
| 3 | +سیاست "Same Origin" (همان سایت) دسترسی پنجرهها و فریمها به یکدیگر را محدود میکند. |
4 | 4 |
|
5 | | -The idea is that if a user has two pages open: one from `john-smith.com`, and another one is `gmail.com`, then they wouldn't want a script from `john-smith.com` to read our mail from `gmail.com`. So, the purpose of the "Same Origin" policy is to protect users from information theft. |
| 5 | +ایده این است که اگر یک یک کاربر دو صفحهی باز داشته باشد: یکی از `john-smith.com` و دیگری از `gmail.com`، آنگاه آنها نمیخواهند که که یک script از `john-smith.com` تمام نامههای شما از `gmail.com` را بخواند. بنابراین، هدف سیاست "Same Origin" این است که کاربران را از دزدی اطلاعات حفظ کند. |
6 | 6 |
|
7 | 7 | ## Same Origin [#same-origin] |
8 | 8 |
|
9 | | -Two URLs are said to have the "same origin" if they have the same protocol, domain and port. |
| 9 | +اگر URLها یک protocol، domain و ports داشته باشند، میگویند که "same origin" دارند. |
10 | 10 |
|
11 | | -These URLs all share the same origin: |
| 11 | +این URLها همگی یک منبع را به اشتراک میگذارند. |
12 | 12 |
|
13 | 13 | - `http://site.com` |
14 | 14 | - `http://site.com/` |
15 | 15 | - `http://site.com/my/page.html` |
16 | 16 |
|
17 | | -These ones do not: |
| 17 | +این یکیها نه: |
18 | 18 |
|
19 | 19 | - <code>http://<b>www.</b>site.com</code> (another domain: `www.` matters) |
20 | 20 | - <code>http://<b>site.org</b></code> (another domain: `.org` matters) |
21 | 21 | - <code><b>https://</b>site.com</code> (another protocol: `https`) |
22 | 22 | - <code>http://site.com:<b>8080</b></code> (another port: `8080`) |
23 | 23 |
|
24 | | -The "Same Origin" policy states that: |
| 24 | +سیاست "Same Origin" بیان میکند که: |
25 | 25 |
|
26 | | -- if we have a reference to another window, e.g. a popup created by `window.open` or a window inside `<iframe>`, and that window comes from the same origin, then we have full access to that window. |
27 | | -- otherwise, if it comes from another origin, then we can't access the content of that window: variables, document, anything. The only exception is `location`: we can change it (thus redirecting the user). But we can't not *read* location (so we can't see where the user is now, no information leak). |
| 26 | +- اگر ما ارجاعی به پنجرهای دیگر داشته باشیم، برای مثال یک popup که با `window.open` ایجاد شده یا یک پنجره داخل `<iframe>`، و آن پنجره از منبع یکسان بیاید،آنگاه ما به آن پنجره دسترسی کامل داریم. |
| 27 | +- ذر غیر این صورت اگر از یک منبع دیگر بیاید، آنگاه نمیتوانیم به محتوای آن صفحه دسترسی داشته باشیم: متغیرها، document، هر چیزی. تنها استثنا `location` است: ما میتوانیم آن را تغییر دهیم. (در نتیجه کاربر را هدایت کنیم). اما نمیتوانیم از location *بخوانیم* (در نتیجه نمیتوانیم ببینیم که کاربر در حال حاضر کجا است، هیچ نشت اطلاعاتی وجود ندارد). |
28 | 28 |
|
29 | | -### In action: iframe |
| 29 | +### در عمل: iframe |
30 | 30 |
|
31 | | -An `<iframe>` tag hosts a separate embedded window, with its own separate `document` and `window` objects. |
| 31 | +یک تگ `<iframe>` میزبان یک پنجرهی جاسازیشدهی جداگانه با `document` جداگانهی خود و اشیای `window` است. |
32 | 32 |
|
33 | | -We can access them using properties: |
| 33 | +میتوان با استفاده از propertyها به آنها دسترسی داشت: |
34 | 34 |
|
35 | | -- `iframe.contentWindow` to get the window inside the `<iframe>`. |
36 | | -- `iframe.contentDocument` to get the document inside the `<iframe>`, shorthand for `iframe.contentWindow.document`. |
| 35 | +- برای گرفتن پنجرهی داخل `<iframe>` از `iframe.contentWindow` استفاده میشود. |
| 36 | +- برای گرفتن documdnt داخل `<iframe>` از `iframe.contentDocument` استفاده میشود، کوتاهشدهی `iframe.contentWindow.document`. |
37 | 37 |
|
38 | | -When we access something inside the embedded window, the browser checks if the iframe has the same origin. If that's not so then the access is denied (writing to `location` is an exception, it's still permitted). |
| 38 | +وقتی به چیزی داخل پنجرهی جاسازی شده دسترسی پیدا میکنیم، مرورگر چک میکند که آیا iframe همان منبع را دارد یا نه. اگر اینطور نباشد، دسترسی رد میشود (نوشتن بر `location` یک استثنا است، آن همچنان مجاز است). |
39 | 39 |
|
40 | 40 | For instance, let's try reading and writing to `<iframe>` from another origin: |
| 41 | +برای مثال، بیایید تلاش کنیم خواندن و نوشتن بر `<iframe>` از یک منبع دیگر را امتحان کنیم. |
41 | 42 |
|
42 | 43 | ```html run |
43 | 44 | <iframe src="https://example.com" id="iframe"></iframe> |
|
0 commit comments