Skip to content

Commit 846dc0f

Browse files
committed
Update "Popups and window methods" article
1 parent 7db561c commit 846dc0f

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

3-frames-and-windows/01-popup-windows/article.md

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,6 @@ button.onclick = () => {
3838

3939
This way users are somewhat protected from unwanted popups, but the functionality is not disabled totally.
4040

41-
What if the popup opens from `onclick`, but after `setTimeout`? That's a bit tricky.
42-
43-
Try this code:
44-
45-
```js run
46-
// open after 3 seconds
47-
setTimeout(() => window.open('http://google.com'), 3000);
48-
```
49-
50-
The popup opens in Chrome, but gets blocked in Firefox.
51-
52-
...If we decrease the delay, the popup works in Firefox too:
53-
54-
```js run
55-
// open after 1 seconds
56-
setTimeout(() => window.open('http://google.com'), 1000);
57-
```
58-
59-
The difference is that Firefox treats a timeout of 2000ms or less are acceptable, but after it -- removes the "trust", assuming that now it's "outside of the user action". So the first one is blocked, and the second one is not.
60-
6141
## window.open
6242

6343
The syntax to open a popup is: `window.open(url, name, params)`:
@@ -87,7 +67,7 @@ Settings for `params`:
8767

8868
There is also a number of less supported browser-specific features, which are usually not used. Check <a href="https://developer.mozilla.org/en/DOM/window.open">window.open in MDN</a> for examples.
8969

90-
## Example: a minimalistic window
70+
## Example: a minimalistic window
9171

9272
Let's open a window with minimal set of features, just to see which of them browser allows to disable:
9373

@@ -120,7 +100,7 @@ Rules for omitted settings:
120100

121101
## Accessing popup from window
122102

123-
The `open` call returns a reference to the new window. It can be used to manipulate it's properties, change location and even more.
103+
The `open` call returns a reference to the new window. It can be used to manipulate its properties, change location and even more.
124104

125105
In this example, we generate popup content from JavaScript:
126106

@@ -239,7 +219,7 @@ There's also `window.onscroll` event.
239219

240220
Theoretically, there are `window.focus()` and `window.blur()` methods to focus/unfocus on a window. And there are also `focus/blur` events that allow to catch the moment when the visitor focuses on a window and switches elsewhere.
241221

242-
Although, in practice they are severely limited, because in the past evil pages abused them.
222+
Although, in practice they are severely limited, because in the past evil pages abused them.
243223

244224
For instance, look at this code:
245225

@@ -257,10 +237,10 @@ Still, there are some use cases when such calls do work and can be useful.
257237

258238
For instance:
259239

260-
- When we open a popup, it's might be a good idea to run a `newWindow.focus()` on it. Just in case, for some OS/browser combinations it ensures that the user is in the new window now.
240+
- When we open a popup, it might be a good idea to run `newWindow.focus()` on it. Just in case, for some OS/browser combinations it ensures that the user is in the new window now.
261241
- If we want to track when a visitor actually uses our web-app, we can track `window.onfocus/onblur`. That allows us to suspend/resume in-page activities, animations etc. But please note that the `blur` event means that the visitor switched out from the window, but they still may observe it. The window is in the background, but still may be visible.
262242

263-
## Summary
243+
## Summary
264244

265245
Popup windows are used rarely, as there are alternatives: loading and displaying information in-page, or in iframe.
266246

0 commit comments

Comments
 (0)