window.open returns null and fails in inline script but works from console

前端 未结 2 1765
刺人心
刺人心 2020-12-07 00:23

I\'m using Smarty template system. One of its features is posibility to output script that generates debug information for every page. Here you can see an example of generat

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 01:26

    It is blocked by the browser. window.open is only not being blocked, when it is invoked by user action, for example in a click event, emitted by a native browser event. Also javaScript emitted events are being blocked, just like delayed setTimeout callbacks.

    StackOverflow
    
    
    

    Watch the Fiddle. I also tried it with the keypress event, but no luck.

    window.open returns a valid reference to the new (or an existing named) window, or null when it failed to create a new window.

提交回复
热议问题