From f9b48983a82f2c88ef288be26012781149a880da Mon Sep 17 00:00:00 2001 From: Olha Brozhenets Date: Mon, 14 Feb 2022 15:37:50 +0200 Subject: [PATCH 01/26] adds cross window communication --- .../03-cross-window-communication/article.md | 268 +++++++++--------- .../postmessage.view/iframe.html | 4 +- .../postmessage.view/index.html | 4 +- .../sandbox.view/index.html | 2 +- .../sandbox.view/sandboxed.html | 4 +- 5 files changed, 141 insertions(+), 141 deletions(-) diff --git a/3-frames-and-windows/03-cross-window-communication/article.md b/3-frames-and-windows/03-cross-window-communication/article.md index 091a0cecb..d2475689d 100644 --- a/3-frames-and-windows/03-cross-window-communication/article.md +++ b/3-frames-and-windows/03-cross-window-communication/article.md @@ -1,130 +1,130 @@ -# Cross-window communication +# Міжвіконна комунікація -The "Same Origin" (same site) policy limits access of windows and frames to each other. +Політика "Одного походження" (одний і той самий сайт) обмежує доступ вікон і фреймів один до одного. -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. +Ідея полягає в тому, що якщо користувач має дві відкриті сторінки: одну з `john-smith.com`, а іншу -- `gmail.com`, тоді він не хоче, щоб сценарій з `john-smith.com` читав нашу пошту з `gmail.com`. Отже, мета політики "Одного походження" -- захистити користувачів від крадіжки інформації. -## Same Origin [#same-origin] +## Політика "Одного походження" [#same-origin] -Two URLs are said to have the "same origin" if they have the same protocol, domain and port. +Кажуть, що дві URL-адреси мають "одне походження", якщо вони мають однаковий протокол, домен і порт. -These URLs all share the same origin: +Усі ці URL-адреси мають одне походження: - `http://site.com` - `http://site.com/` - `http://site.com/my/page.html` -These ones do not: +А ці ні: -- http://www.site.com (another domain: `www.` matters) -- http://site.org (another domain: `.org` matters) -- https://site.com (another protocol: `https`) -- http://site.com:8080 (another port: `8080`) +- http://www.site.com (інший домен: `www.` має значення) +- http://site.org (інший домен: `.org` має значення) +- https://site.com (інший протокол: `https`) +- http://site.com:8080 (інший порт: `8080`) -The "Same Origin" policy states that: +У політиці "Одного походження" зазначено, що: -- if we have a reference to another window, e.g. a popup created by `window.open` or a window inside ` ``` -The code above shows errors for any operations except: +Код вище показує помилки для будь-яких операцій, крім: -- Getting the reference to the inner window `iframe.contentWindow` - that's allowed. -- Writing to `location`. +- Отримання посилання на внутрішнє вікно `iframe.contentWindow` -- це дозволено. +- Запис до `location`. -Contrary to that, if the ` ``` ```smart header="`iframe.onload` vs `iframe.contentWindow.onload`" -The `iframe.onload` event (on the ` @@ -156,26 +156,26 @@ We can try to catch the moment earlier using checks in `setInterval`: ``` -## Collection: window.frames +## Колекція: window.frames -An alternative way to get a window object for ` @@ -186,93 +186,93 @@ For instance: ``` -An iframe may have other iframes inside. The corresponding `window` objects form a hierarchy. +Усередині iframe можуть бути інші iframe. Відповідні об’єкти `window` утворюють ієрархію. -Navigation links are: +Навігаційні посилання: -- `window.frames` -- the collection of "children" windows (for nested frames). -- `window.parent` -- the reference to the "parent" (outer) window. -- `window.top` -- the reference to the topmost parent window. +- `window.frames` -- колекція дочірніх вікон (для вкладених фреймів). +- `window.parent` -- посилання на "батьківське" (зовнішнє) вікно. +- `window.top` -- посилання на найвище батьківське вікно. -For instance: +Наприклад: ```js run window.frames[0].parent === window; // true ``` -We can use the `top` property to check if the current document is open inside a frame or not: +Ми можемо використовувати властивість `top`, щоб перевірити, чи відкритий поточний документ у фреймі чи ні: ```js run if (window == top) { // current window == window.top? - alert('The script is in the topmost window, not in a frame'); + alert('Скрипт знаходиться у верхньому вікні, а не у фреймі'); } else { - alert('The script runs in a frame!'); + alert('Скрипт виконується у фреймі!'); } ``` -## The "sandbox" iframe attribute +## Атрибут iframe "sandbox". -The `sandbox` attribute allows for the exclusion of certain actions inside an ` diff --git a/3-frames-and-windows/03-cross-window-communication/sandbox.view/index.html b/3-frames-and-windows/03-cross-window-communication/sandbox.view/index.html index 46dd7b5cc..f3cfd1789 100644 --- a/3-frames-and-windows/03-cross-window-communication/sandbox.view/index.html +++ b/3-frames-and-windows/03-cross-window-communication/sandbox.view/index.html @@ -7,7 +7,7 @@ -
The iframe below has the sandbox attribute.
+
Наведений нижче iframe має атрибут sandbox.
diff --git a/3-frames-and-windows/03-cross-window-communication/sandbox.view/sandboxed.html b/3-frames-and-windows/03-cross-window-communication/sandbox.view/sandboxed.html index c10273255..93793f9c1 100644 --- a/3-frames-and-windows/03-cross-window-communication/sandbox.view/sandboxed.html +++ b/3-frames-and-windows/03-cross-window-communication/sandbox.view/sandboxed.html @@ -7,11 +7,11 @@ - +
- +
From 58f478c356a2331602095ca95540fbaa7f0e3aaf Mon Sep 17 00:00:00 2001 From: Olha Brozhenets Date: Mon, 14 Feb 2022 16:24:07 +0200 Subject: [PATCH 02/26] edits cross window communication --- .../03-cross-window-communication/article.md | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/3-frames-and-windows/03-cross-window-communication/article.md b/3-frames-and-windows/03-cross-window-communication/article.md index d2475689d..a9b5095c1 100644 --- a/3-frames-and-windows/03-cross-window-communication/article.md +++ b/3-frames-and-windows/03-cross-window-communication/article.md @@ -23,7 +23,7 @@ У політиці "Одного походження" зазначено, що: -- якщо ми маємо посилання на інше вікно, напр. спливаюче вікно, створене за допомогою `window.open` або вікна всередині ` From 54d268a5a8a8b9b32277766c2fd7301cae4d056c Mon Sep 17 00:00:00 2001 From: Stanislav Date: Mon, 4 Apr 2022 09:51:38 +0300 Subject: [PATCH 16/26] Update 3-frames-and-windows/03-cross-window-communication/article.md --- 3-frames-and-windows/03-cross-window-communication/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3-frames-and-windows/03-cross-window-communication/article.md b/3-frames-and-windows/03-cross-window-communication/article.md index 87becf575..cdaefac1e 100644 --- a/3-frames-and-windows/03-cross-window-communication/article.md +++ b/3-frames-and-windows/03-cross-window-communication/article.md @@ -35,7 +35,7 @@ - `iframe.contentWindow`, щоб отримати вікно всередині ` @@ -156,14 +156,14 @@ document.domain = 'site.com'; ``` @@ -204,7 +204,7 @@ window.frames[0].parent === window; // true ```js run if (window == top) { // current window == window.top? - alert('Скрипт знаходиться у верхньому вікні, а не у фреймі'); + alert('Скрипт знаходиться у батьківському вікні, а не у фреймі'); } else { alert('Скрипт виконується у фреймі!'); } @@ -212,16 +212,16 @@ if (window == top) { // current window == window.top? ## Атрибут iframe "sandbox" -Атрибут `sandbox` дозволяє виключити певні дії всередині `