Why is window.open() silently ignored iff called from within a loop and via setTimeout()?

前端 未结 1 924
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 02:25

--- EDIT.

I don\'t get it; yesterday it seemed to be ignored; now it seems to be working. Even within loop and called via setTimeout()

1条回答
  •  太阳男子
    2021-01-17 02:47

    Popup blockers in most popular browsers will only allow a new window to be opened if it is opened as a result of code running from a direct user action such as a click. Because a setTimeout() happens some time in the future, is not considered the direct result of a user action so attempts to open windows from setTimeout() are likely blocked by the popup blocker.

    In essence, trying to fire window.open from within setTimeout() leaves the browser to "think" it's a popup which deserves (silent) blocking. -- If, in contrast, window.open is fired on it's own, the browser treats seems to treat it like a "user click", that is, not as spam to be blocked.

    0 讨论(0)
提交回复
热议问题