one

In general, if you call window.open() directly in JS to open a new window, the browser will block the pop-up window because the browser will think that the window is a pop-up AD or other form that the user does not want

The solution

Change the window.open() function to be triggered when the user clicks, and add an onclick event to the hyperlink so that the browser thinks the user wants to visit the page instead of popping it up to the user

example

 <a href="javascript:void(0)" onclick="window.open()"></a>
Copy the code

When the user clicks on the hyperlink, the browser thinks it’s opening a new link, so it won’t block it.

two

Using Ajax to process data, when the click to get data, and then jump to a new page, it will be blocked by the browser

The solution

Open opens a window with window.open and then changes the address of the window

example

var tempwindow=window.open();
tempwindow.location='/jump/new';
Copy the code

three

let aDom = document.createElement('a');
aDom.target = '_blank';
aDom.href = url;
aDom.click();
Copy the code

Source link: www.jb51.net/article/901…