diff --git a/3-frames-and-windows/01-popup-windows/article.md b/3-frames-and-windows/01-popup-windows/article.md index e90d6a7b..fbefc469 100644 --- a/3-frames-and-windows/01-popup-windows/article.md +++ b/3-frames-and-windows/01-popup-windows/article.md @@ -11,12 +11,12 @@ window.open('https://javascript.info/') Popups exist from really ancient times. The initial idea was to show another content without closing the main window. As of now, there are other ways to do that: we can load content dynamically with [fetch](info:fetch) and show it in a dynamically generated `
`. So, popups is not something we use everyday. -Also, popups are tricky on mobile devices. +Also, popups are tricky on mobile devices, that don't show multiple windows simultaneously. -Still, there are situations when a popup works good, e.g. for OAuth authorization (login with Google/Facebook/...), because: +Still, there are tasks where popups are still used, e.g. for OAuth authorization (login with Google/Facebook/...), because: 1. A popup is a separate window with its own independent JavaScript environment. So opening a popup with a third-party non-trusted site is safe. -2. It's very easy to open a popup, little to no overhead. +2. It's very easy to open a popup. 3. A popup can navigate (change URL) and send messages to the opener window. ## Popup blocking @@ -149,7 +149,7 @@ newWindow.onload = function() { Please note: immediately after `window.open`, the new window isn't loaded yet. That's demonstrated by `alert` in line `(*)`. So we wait for `onload` to modify it. We could also use `DOMContentLoaded` handler for `newWin.document`. ```warn header="Same origin policy" -Windows may only freely modify each other if they come from the same origin (the same protocol://domain:port). +Windows may freely access content of each other only if they come from the same origin (the same protocol://domain:port). Otherwise, e.g. if the main window is from `site.com`, and the popup from `gmail.com`, that's impossible for user safety reasons. For the details, see chapter . ``` @@ -158,7 +158,7 @@ Otherwise, e.g. if the main window is from `site.com`, and the popup from `gmail A popup may access the "opener" window as well using `window.opener` reference. It is `null` for all windows except popups. -If you run the code below, it replaces the opener window content with "Test": +If you run the code below, it replaces the opener (current) window content with "Test": ```js run let newWin = window.open("about:blank", "hello", "width=200,height=200"); @@ -172,12 +172,13 @@ So the connection between the windows is bidirectional: the main window and the ## Closing a popup -- To close a window: `win.close()`. -- To check if a window is closed: `win.close` property. +To close a window: `win.close()`. + +To check if a window is closed: `win.closed`. Technically, the `close()` method is available for any `window`, but `window.close()` is ignored by most browsers if `window` is not created with `window.open()`. So it'll only work on a popup. -The `win.closed` property is `true` if the window is closed. That's useful to check if the popup (or the main window) is still open or not. A user can close it anytime, and our code should take that possibility into account. +The `closed` property is `true` if the window is closed. That's useful to check if the popup (or the main window) is still open or not. A user can close it anytime, and our code should take that possibility into account. This code loads and then closes the window: @@ -259,23 +260,18 @@ For instance: ## Summary -Всплывающие окна используются нечасто. Ведь загрузить новую информацию можно динамически, с помощью технологии AJAX, а показать -- в элементе `
`, расположенным над страницей (`z-index`). Ещё одна альтернатива -- тег `