You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 3-frames-and-windows/01-popup-windows/article.md
+16-3
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ A popup window is one of the oldest methods to show additional document to user.
4
4
5
5
Basically, you just run:
6
6
```js
7
-
window.open('http://javascript.info/')
7
+
window.open('https://javascript.info/')
8
8
```
9
9
10
10
... 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
17
17
18
18
**Most browsers block popups if they are called outside of user-triggered event handlers like `onclick`.**
19
19
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.
0 commit comments