A window is blocked because a new page is opened using window.open(url), but most browsers will block it. Most modern browsers (Chrome/Firefox/IE 10+ / Safari) have popup blocking enabled by default, because window.open is being abused by advertisers and can seriously affect user usage. The popup blocking operation does not directly block windw.open(), but determines whether window.open() is a rogue operation based on the user’s behavior.

Window.open is not blocked, it is blocked conditionally, is the time between the click time and your open, if there is a time difference (some browsers allow a little time difference), the browser will consider you unsafe, and will block you.

The solution

Method 1: Use jQuery to simulate click events

Jquery provides methods that simulate the click event, $(selector).click(). It is important to note that the <a> tag must have content in it when the a tag click is triggered, and it must simulate the content inside the tag being clicked rather than < A ></a> being clicked. $("span").click();Copy the code

Method 2: use native JS to simulate click events

 document.getElementById("test2").click();Copy the code

Method 3: createEvent + initEvent + dispatchEvent

Document.createevent is used to create events. In DOM Level 2 events there are HTMLEvents, MouseEvents, UIEvents events. The initEvent() method is used to initialize the value of the Event created through the DocumentEvent interface. A dispatchEvent triggers an event on the corresponding element.Copy the code

Mode 4: Rear redirection

This method requires the cooperation of the back end. First provide an interface address, the front end jumps to the address through the A label, and the back end directly redirects to the target address after calculation. This is also a convenient and quick method.Copy the code