The problem that js was blocked when opening a new window.

also found a lot of information on the Internet. creating a tag to simulate user clicks will still be blocked . The problem I found is that if I immediately pop up a new window, it will not be blocked but our current requirement is to call an interface before opening it and then successfully return to open a new window. Is there any good way to solve the problem?

Mar.14,2021

it is recommended not to use cool techs. Since browsers don't want you to do so, it means that cool techs that is successful today may not be available after a while.


simulate a tag click, and the interface gets the address to create a tag to add to the body and use js to click to destroy.

var a=document.createElement('a');
    a.href='https://www.baidu.com'//
    a.target='_blank';
    document.body.appendChild(a)
    a.click();

blocking reason: when JS script triggers a link or form submission, it will be blocked by the browser. This is the browser's security defense mechanism. You can also set the browser settings to allow new windows to open unconditionally.
this method will not be blocked: after the API request is successful, you first var openNewWindow = window.open ("", "_ blank"), open an empty new page, and then redirect your url to the new page openNewWindow.location.href = "- sharp-sharp-sharp".


there is another way: change the ajax request to Synchronize, and after the request is returned, use window.open (url)


you can first write a tag on the page, and then dynamically change his url, finally using js to simulate click events, so it's OK. (just tried, it seems to have been intercepted)


did the landlord find the answer? ask for advice. I also want to use JS to automatically click on the hyperlink and open a new window without being blocked.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eadbc6-217c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eadbc6-217c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?