Skip to content

Commit a9d2176

Browse files
committed
popup
1 parent eb43d82 commit a9d2176

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A popup window is one of the oldest methods to show additional document to user.
44

55
Basically, you just run:
66
```js
7-
window.open('http://javascript.info/')
7+
window.open('https://javascript.info/')
88
```
99

1010
... And it will open a new window with given URL. Most modern browsers are configured to open new tabs instead of separate windows.
@@ -17,7 +17,20 @@ In the past evil sites abused popups a lot. A bad page could open tons of popup
1717

1818
**Most browsers block popups if they are called outside of user-triggered event handlers like `onclick`.**
1919

20-
If you think about it, that's a bit tricky. If the code is directly in an `onclick` handler, then that's easy. But what is the popup opens in `setTimeout`?
20+
For example:
21+
```js
22+
// popup blocked
23+
window.open('https://javascript.info');
24+
25+
// popup allowed
26+
button.onclick = () => {
27+
window.open('https://javascript.info');
28+
};
29+
```
30+
31+
This way users are somewhat protected from unwanted popups, but the functionality is not disabled totally.
32+
33+
What if the popup opens from `onclick`, but after `setTimeout`? That's a bit tricky.
2134

2235
Try this code:
2336

@@ -28,7 +41,7 @@ setTimeout(() => window.open('http://google.com'), 3000);
2841

2942
The popup opens in Chrome, but gets blocked in Firefox.
3043

31-
...And this works in Firefox too:
44+
...If we decrease the delay, the popup works in Firefox too:
3245

3346
```js run
3447
// open after 1 seconds

0 commit comments

Comments
 (0)