最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Why does browser block popup windows in callback but not otherwise - Stack Overflow

matteradmin3PV0评论

Strange behavior - Im trying to open a new window in a callback - using Angular but probably a general JS issue.

If I do this:

$window.open('', '_blank');

It works fine. However this doesn't as it gets blocked by my browser - I am using Safari 7 and have "block popup windows" checked:

Items.list(function(items) {
  $window.open('', '_blank')
});

Why does the browser block that and not the other and how can I circumvent this? I played with setTimeout as well as some SO post suggestion to assign $window.open to a variable before calling async but did not work here.

Strange behavior - Im trying to open a new window in a callback - using Angular but probably a general JS issue.

If I do this:

$window.open('http://google.', '_blank');

It works fine. However this doesn't as it gets blocked by my browser - I am using Safari 7 and have "block popup windows" checked:

Items.list(function(items) {
  $window.open('http://google.', '_blank')
});

Why does the browser block that and not the other and how can I circumvent this? I played with setTimeout as well as some SO post suggestion to assign $window.open to a variable before calling async but did not work here.

Share Improve this question asked Jan 3, 2014 at 4:22 cyberwombatcyberwombat 40.2k41 gold badges184 silver badges267 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Popup blocker logic often blocks popup windows when the popup window is not opened as a direct consequence of a user action (like a click).

A callback that happens asynchronously is NOT a direct consequence of a user action - it's sometime later and is not directly connected to that action (as the browser sees it), thus the browser may not allow it.

The usual work-around is to open the popup window immediately (as a direct consequence of the user action) and then populate its content later after the asynchronous callback occurs and the content is available.

Does angular 6 support popup window like javascript? I am not looking for a modal window solution. I want to be able move the window to another screen like you can do with JavaScript popup windows. Is there any documentation on that? How can you go about doing it on Angular 5/6 ie to open a pop up window

Post a comment

comment list (0)

  1. No comments so far